include iostream include vector include string using namespace std dou

 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
#include<iostream>
#include<vector>
#include<string>
using namespace std;
double ver(vector<vector<double> > t, vector<pair<int, int> > a, int k)
{
double ans = 0;
t[0][0] = 1;
for (int i = 0; i <= k; ++i)
for (int j = 0; j < a[0].first; ++j)
{
if (t[i][j] != 0)
for (int q = 1; q < a.size(); ++q)
{
if (i + a[q].first > k)
ans += t[i][j] / (a.size() - 1);
if (a[q].second)
t[i + a[q].first][j] += t[i][j] / (a.size() - 1);
else
t[i + a[q].first][j + 1] += t[i][j] / (a.size() - 1);
}
}
return ans;
}
int main()
{
int n, m, k, r = 0;
cin >> n;
vector< vector<pair<int, int> > > bone(n, vector<pair<int, int> > (1));
for (int i = 0; i < n; ++i)
{
cin >> bone[i][0].first >> m;
if (r < bone[i][0].first) r = bone[i][0].first;
for (int j = 0; j < m; ++j)
{
string s;
cin >> s;
if (s[0] == '+')
bone[i].push_back(make_pair(s[1] - '0', 1) );
else
{
int q = s[0] - '0';
if (s.size() > 1)
q = (s[0] - '0') * 10 + s[1] - '0';
bone[i].push_back(make_pair(q, 0));
}
}
}
cin >> k;
vector<vector<double> > t(bone[0][0].first * bone[0].size(), vector<double>(r + 1, 0));
vector<double> ans(n, 0);
for (int i = 1; i <= k; ++i)
{
for (int j = 0; j < n; ++j)
ans[j] = ver(t, bone[j], i);
int p = 0;
for (int j = 1; j < n; ++j)
if (ans[p] < ans[j]) p = j;
cout << p + 1 << endl;
}
return 0;
}