-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathNisoku.cpp
58 lines (52 loc) · 1.31 KB
/
Nisoku.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
using namespace std;
class Nisoku {
public:
double f(vector<double> cs) {
if (cs.size() == 2)
return max(cs[0]*cs[1], cs[0]+cs[1]);
double m = 0;
for (int i = 0; i < cs.size(); ++i) {
for (int j = i+1; j < cs.size(); ++j) {
vector<double> tmp = cs;
tmp.erase(tmp.begin()+i);
tmp.erase(tmp.begin()+j-1);
double x = f(tmp);
double a = (cs[i]*cs[j])*x;
double b = (cs[i]*cs[j])+x;
double c = (cs[i]+cs[j])*x;
double d = (cs[i]+cs[j])+x;
m = max(m, max(a, max(b, max(c, d))));
}
}
return m;
}
double theMax(vector <double> cs) {
return f(cs);
}
};
int main() {
vector<double> x;
x.push_back(8.26);
x.push_back(7.54);
x.push_back(3.2567);
Nisoku n;
cout << n.theMax(x) << endl;
return 0;
}