-
Notifications
You must be signed in to change notification settings - Fork 24
/
Jewelry.cpp
129 lines (111 loc) · 3.59 KB
/
Jewelry.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#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;
typedef vector<int> VI;
class Jewelry {
public:
static const int max_pieces = 35;
static const int max_value = 1005;
void calc(VI::iterator a, VI::iterator b, long long t[], long long s) {
VI::iterator i;
long long tmp[max_value*max_pieces];
memset(t, 0, sizeof(long long)*max_value*max_pieces);
// cout << endl;
// cout << "uzywam: ";
for (i = a; i != b; i++) {
memset(tmp, 0, sizeof(long long)*max_value*max_pieces);
// cout << *i << " ";
for (int j = 1; j <= s; ++j) {
if (t[j]) {
tmp[j+(*i)] += t[j];
}
}
tmp[*i]++;
for (int j = 1; j <= s; ++j) {
t[j] += tmp[j];
}
}
// cout << endl;
}
long long howMany(VI vs) {
long long ta[max_value*max_pieces];
long long tb[max_value*max_pieces];
long long tmp[max_value*max_pieces];
long long result = 0;
long long sa = vs[0];
long long sb = 0;
VI::iterator ii;
memset(ta, 0, sizeof(long long)*max_value*max_pieces);
for (int i = 1; i < vs.size(); ++i)
sb += vs[i];
sort(vs.begin(), vs.end());
for (int i = 1; i < vs.size(); ++i) {
// cout << "a (" << sa << ") : ";
// for (int j = 0; j < i; ++j) {
// cout << vs[j] << " ";
// }
// cout << endl;
// calc(vs.begin(), vs.begin()+i, ta, min(sa, sb));
for (int j = 1; j <= sa; ++j) {
if (ta[j]) {
tmp[j+vs[i-1]] += ta[j];
}
}
tmp[vs[i-1]]++;
// cout << endl;
cout << "tmp: ";
for (int j = 1; j < 20; ++j) {
cout << j << " ";
}
cout << endl;
cout << "tmp: ";
for (int j = 1; j < 20; ++j) {
cout << tmp[j] << " ";
}
cout << endl;
calc(vs.begin()+i, vs.end(), tb, min(sa, sb));
cout << "b (" << sb << ") : ";
for (int j = i; j < vs.size(); ++j) {
cout << vs[j] << " ";
}
cout << endl;
cout << "b: ";
for (int j = 1; j < 20; ++j) {
cout << j << " ";
}
cout << endl;
cout << "b: ";
for (int j = 1; j < 20; ++j) {
cout << tb[j] << " ";
}
cout << endl;
for (int j = 0; j < max_pieces*max_value; ++j) {
if (tmp[j] && tb[j]) {
result += tmp[j]*tb[j];
}
}
for (int j = 1; j <= sa; ++j) {
ta[j] += tmp[j];
}
memset(tmp, 0, sizeof(long long)*max_value*max_pieces);
sa += vs[i];
sb -= vs[i];
}
return result;
}
};