标签:
题目大意:
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<queue> #include<cmath> using namespace std; #define INF 0x3fffffff typedef __int64 LL; const LL maxn = 2005; const LL mod = 1e9+7; int A[maxn], B[maxn], W[maxn], dp[maxn][maxn*2]; int T, n, m, w; int main() { scanf("%d", &T); while(T--) { scanf("%d %d", &m, &n); for(int i=1; i<=n; i++) scanf("%d %d %d", &W[i], &A[i], &B[i]); memset(dp, -1, sizeof(dp)); dp[0][0] = 0; int ans = 0; for(int i=1; i<=n; i++) { for(int j=W[i]; j<=m; j++) { if(dp[i-1][j-W[i]] != -1) dp[i][j] = dp[i-1][j-W[i]] + A[i] + B[i]; if(dp[i][j-W[i]] != -1) dp[i][j] = max(dp[i][j], dp[i][j-W[i]] + A[i]); ans = max(ans, dp[i][j]); } for(int j=0; j<=m; j++) dp[i][j] = max(dp[i][j], dp[i-1][j]); } printf("%d\n", ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/chenchengxun/p/4746960.html