洛谷 P1802 5倍经验日

题目传送门

解题思路:

01背包,但要注意的是,这道题对于每个人,打输了也会有收益.

AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 
 4 using namespace std;
 5 
 6 long long n,x,f[1001];
 7 struct kkk{
 8     int l,w,v;
 9 }e[1001];
10 
11 int main() {
12     scanf("%lld%lld",&n,&x);
13     for(int i = 1;i <= n; i++)
14         scanf("%d%d%d",&e[i].l,&e[i].w,&e[i].v);
15     for(int i = 1;i <= n; i++)
16         for(int j = x;j >= 0; j--)
17             if(j >= e[i].v)
18                 f[j] = max(f[j] + e[i].l,f[j-e[i].v] + e[i].w);
19             else
20                 f[j] = f[j] + e[i].l;
21     printf("%lld",f[x] * 5);
22     
23     return 0;
24 }
原文地址:https://www.cnblogs.com/lipeiyi520/p/11986327.html