P1802
(日常切水题......)
打人游戏,打不赢获得lose[i],打赢获得win[i],显然win[]>lose[],首先我们肯定可以获得所有的lose,那么打赢每个人就相当于可以获得win-lose,代价为use[i],那么这道题就是一个01背包问题了。
(放张可莉压压惊......)
1 #include <bits/stdc++.h> 2 #define int long long 3 using namespace std; 4 const int N = 1010; 5 int n, x, w[N], v[N]; 6 int f[N], ans; 7 signed main() { 8 cin >> n >> x; 9 for (int i = 1; i <= n; i ++) { 10 int a, b, c; cin >> a >> b >> c; 11 ans += a, v[i] = b - a, w[i] = c; 12 } 13 for (int i = 1; i <= n; i ++) 14 for (int j = x; j >= w[i]; j --) 15 f[j] = max(f[j], f[j - w[i]] + v[i]); 16 ans += f[x]; 17 cout << 5 * ans << '\n'; 18 return 0; 19 }标签:经验,int,win,lose,long,P1802,ans From: https://www.cnblogs.com/YHxo/p/16775802.html