define _CRT_SECURE_NO_WARNI NGS include iostream include vector includ

 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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, f, k;
cin >> n;
vector<int> times(n);
vector<vector<int> > val(n), sign(n);
for (int i = 0; i < n; i++) {
cin >> times[i];
cin >> f;
string s;
sign[i].assign(f, 0);
val[i].resize(f);
for (int j = 0; j < f; j++) {
cin >> s;
if (s[0] == '+')
sign[i][j] = 1;
val[i][j] = atoi(s.data());
}
}
cin >> k;
vector<int> ans(k + 1, 0);
vector<double> ans_prob(k + 1, 0);
for (int i = 0; i < n; i++) {
vector<vector<double> > dp(times[i] + 1, vector<double>(k + 1, 0));
dp[0][0] = 1.0;
for (int tm = 1; tm < times[i] + 1; tm++) {
for (int pts = 1; pts < k + 1; pts++) {
double d = 0;
for (int g = 0; g < val[i].size(); g++) {
if (pts - val[i][g] < 0)
continue;
if (sign[i][g])
d += dp[tm][pts - val[i][g]];
else
d += dp[tm - 1][pts - val[i][g]];
}
dp[tm][pts] += (d / val[i].size());
}
}
double cur = dp[times[i]][0];
for (int j = 1; j < k + 1; j++) {
if (ans_prob[j] < 1 - cur) {
ans_prob[j] = 1 - cur;
ans[j] = i;
}
cur += dp[times[i]][0];
}
}
for (int i = 1; i < k + 1; i++) {
cout << ans[i] << endl;
}
/* for (int i = 0; i < n; i++) {
for (int j = 0; j < val[i].size(); j++)
cout << val[i][j] << " ";
cout << endl;
}
cout << endl << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < sign[i].size(); j++)
cout << sign[i][j] << " ";
cout << endl;
}*/
return 0;
}