Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2159
Test instructions: Play strange, there is the last level, endurance limited m, asked in the case of the number of monsters to kill the maximum amount of s can get n experience and customs clearance, and patience to spend less the better.
Analysis: Dp[i][j] indicates that the maximum XP value obtained by the number of I spent endurance for J was played.
State transition equation: Dp[i][j]=max (dp[i][j],dp[i-1][j-w[i]]+p[i])
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 10010using namespacestd;intdp[ the][ the],w[ the],p[ the];intMain () {intn,m,s,k; while(SCANF ("%d%d%d%d", &n,&m,&k,&s) >0) { for(intI=1; i<=k;i++) scanf ("%d%d",&p[i],&W[i]); Memset (DP,-1,sizeof(DP)); memset (dp[0],0,sizeof(dp[0])); for(intI=1; i<=k;i++) for(intj=w[i];j<=m;j++) for(intK=s;k>0; k--) { if(dp[k-1][j-w[i]]!=-1) Dp[k][j]=max (dp[k][j],dp[k-1][j-w[i]]+P[i]); } intans=-1; for(intI=1; i<=s;i++) for(intj=1; j<=m;j++) if(dp[i][j]>=N) {ans=max (ANS,M-J); Break; } printf ("%d\n", ans); }}View Code
hdu2159 (two-dimensional full backpack)