【DP】 HDOJ 5410 CRB and His Birthday

来源:互联网 发布:磊科网络尖兵设置 编辑:程序博客网 时间:2024/04/27 14:27

先做一遍01背包,再做一遍多重背包。

#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 2005;int dp[maxn];void work(){int n, m;memset(dp, 0, sizeof dp);scanf("%d%d", &n, &m);while(m--) {int a, b, c;scanf("%d%d%d", &c, &a, &b);for(int i = n; i >= c; i--) dp[i] = max(dp[i], dp[i-c] + a + b);for(int i = c; i <= n; i++) dp[i] = max(dp[i], dp[i-c] + a);}printf("%d\n", dp[n]);}int main(){int _;scanf("%d", &_);while(_--) work();return 0;}


0 0
原创粉丝点击