Analysis: Dp[l][i][j][k] represents the maximum value that can be obtained when I spend I, Integral J, free p when I select the first L pieces. The k value is also counted as a backpack.
State transition equation:
Dp[l][i][j][k] = max (Dp[l][i][j][k], dp[l-1][i-a[l]][j][k]+c[i], dp[l-1][i][j-b[l]][k]+c[i], dp[l-1][i][i][k-1]+c[i ]) (k > 0, I >= a[l], J >= B[l], k= 1,2,3,4....N)
A[L] Indicates the amount of money to be used in cash, b[l] represents the number of points to be spent in the conversion of the integral of the L type.
#include <iostream>using namespace Std;int dp[101][101][6]; Dp[l][i][j][k], the choice of l pieces of goods cost I yuan, J integral, p free is the maximum value obtained, rolling array minus one-dimensional int a[101],b[101],c[101];int n,v1,v2,k; #define MAX (A, B) ((a) > (b)? (a):(b)) int sovle () {int I,j,kk,l,ans;memset (dp,0,sizeof (DP)); for (i=0;i<n;i++) for (j=v1;j>=0;j--) for (KK=V2; kk>=0;kk--) for (l=k;l>=0;l--) {ans=0;if (J>=a[i]) Ans=max (Ans,dp[j-a[i]][kk][l]+c[i]), if (Kk>=b[i]) ans= Max (Ans,dp[j][kk-b[i]][l]+c[i]), if (l>=1) Ans=max (Ans,dp[j][kk][l-1]+c[i]);DP [J][kk][l]=max (Ans,dp[j][kk][l]) ;} return dp[v1][v2][k];} int main () {int I;while (cin>>n>>v1>>v2>>k) {for (i=0;i<n;i++) Cin>>a[i]>>b[i] >>c[i];cout<<sovle () <<endl;} return 0;}
HDU ACM 4501 Xiao Ming series story--Buy the multi-dimensional backpack (more than 01 backpack)