http://acm.hdu.edu.cn/showproblem.php?pid=4501
多维背包
代码:
#include<iostream> #include<cmath> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #define LL long long using namespace std; const int INF=0x3f3f3f3f; const int MOD=100000; const LL LMOD=100000; const int N=105; const int M=105; const int K=6; int dp[N][M][K]; void pack01ThreeD(int a,int b,int c,int v,int A,int B,int C) { for(int i=A;i>=0;--i) for(int j=B;j>=0;--j) for(int l=C;l>=0;--l) { int tmp=0; if(i-a>=0) tmp=max(tmp,dp[i-a][j][l]+v); if(j-b>=0) tmp=max(tmp,dp[i][j-b][l]+v); if(l-c>=0) tmp=max(tmp,dp[i][j][l-c]+v); dp[i][j][l]=max(dp[i][j][l],tmp); } } int main() { //freopen("data.in","r",stdin); int n,A,B,C; while(scanf("%d %d %d %d",&n,&A,&B,&C)!=EOF) { memset(dp,0,sizeof(dp)); while(n--) { int a,b,v; scanf("%d %d %d",&a,&b,&v); pack01ThreeD(a,b,1,v,A,B,C); } printf("%d\n",dp[A][B][C]); } return 0; }