标签:
5 10000 3 1 4 6 2 5 7 3 4 99 1 55 77 2 44 66
255
1 #include <bits/stdc++.h> 2 #define pii pair<int,int> 3 using namespace std; 4 const int maxn = 110; 5 int n,m,o,dp[11][10001]; 6 vector< pii >goods[maxn]; 7 int main(){ 8 int a,b,c; 9 while(~scanf("%d %d %d",&n,&m,&o)){ 10 for(int i = 0; i < maxn; ++i) goods[i].clear(); 11 for(int i = 0; i < n; ++i){ 12 scanf("%d %d %d",&a,&b,&c); 13 goods[a].push_back(make_pair(b,c)); 14 } 15 memset(dp,-1,sizeof dp); 16 memset(dp[0],0,sizeof dp[0]); 17 for(int i = 1; i <= o; ++i){ 18 for(int j = 0; j < goods[i].size(); ++j){ 19 for(int k = m; k >= goods[i][j].first; --k){ 20 if(dp[i][k - goods[i][j].first] >= 0) 21 dp[i][k] = max(dp[i][k],dp[i][k-goods[i][j].first] + goods[i][j].second); 22 if(dp[i-1][k - goods[i][j].first] >= 0) 23 dp[i][k] = max(dp[i][k],dp[i-1][k-goods[i][j].first] + goods[i][j].second); 24 } 25 } 26 } 27 if(dp[o][m] >= 0) printf("%d\n",dp[o][m]); 28 else puts("Impossible"); 29 } 30 return 0; 31 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4448332.html