-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1064.cpp
62 lines (62 loc) · 1.45 KB
/
P1064.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
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct goods
{
int v, p;
int q_num;
bool top;
int q[3]; // 价格、重要程度、附件的数目
};
struct goods g[61];
int dp[32001];
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int v, p, q;
cin >> v >> p >> q;
if (!q)
{
g[i].v = v;
g[i].p = p;
g[i].q_num = 0;
g[i].top = true;
}
else
{
g[i].v = v;
g[i].p = p;
g[i].q_num = 0;
g[i].top = false;
g[q].q[g[q].q_num] = i;
g[q].q_num++;
}
}
for (int i = 1; i <= m; i++)
{
for (int j = n; j >= 10; j-=10)
{
if (!g[i].top)
{
continue;
}
if (j >= g[i].v)
{
dp[j] = max(dp[j], dp[j-g[i].v]+g[i].v*g[i].p);
}
if(g[i].q_num>=1&&j>=g[g[i].q[0]].v+g[i].v){
int q_0=g[i].q[0];
dp[j]=max(dp[j],dp[j-g[q_0].v-g[i].v]+g[i].v*g[i].p+g[q_0].v*g[q_0].p);
}
if(g[i].q_num>=2&&j>=g[g[i].q[0]].v+g[i].v+g[g[i].q[1]].v){
int q_0=g[i].q[0];
int q_1=g[i].q[1];
dp[j]=max(dp[j],dp[j-g[q_0].v-g[q_1].v-g[i].v]+g[i].v*g[i].p+g[q_1].v*g[q_1].p+g[q_0].v*g[q_0].p);
}
}
}
cout<<dp[n];
return 0;
}