Meaning of the questions:
There are n days, m kinds of investment programs, and the balance at less subsidies f k [x].
Every day you can choose to invest in an unlimited number of investment programs (but to ensure that balance is greater than or equal to 0), return on investment will be after the end of the n-day return.
Seeking maximum return on investment is how much.
Ideas:
This investment money, then the last harvest can be converted to a full knapsack problem. And because the state of the balance of diverse every day, so every day begins should be transferred to the state.
Provided dp [i] [j] for the i-th day, the balance j. Then the state transition starts every day: dp [i] [j + f [j]] = max (dp [i] [j + f [j]], dp [i-1] [j]); // f [ j] is a function of subsidies
Then on the same day transferred completely backpack
code: (see other code comments)
#include <the iostream> #include <cstdio> #include <CString> the using namespace STD; const int INF = 0x3f3f3f3f ; int F [ 2050 ]; // (0 <= K <= 1000), (K + F [K] <= 2000) int V [ 110 ], W [ 110 ]; // (. 1 <= m <= 100) int DP [ 105 ] [ 3005 ]; // max (I + F [I]) int main () { int n-, m, K; CIN >> >> m >> n- K; // day hand the remaining money to the maximum int mmax = 0; for(int i=0;i<=k;i++){ scanf("%d",&f[i]); mmax = max(mmax,f[i]+i); } for(int i=1;i<=m;i++){ scanf("%d%d",&v[i],&w[i]); } memset(dp,-inf,sizeof(dp)); dp[1][0]=0; for(int l=2;l<=n;l++){ for(int j=0;j<=k;j++) dp[l][j+f[j]]=max(dp[l][j+f[j]],dp[l-1][j]); for(int i=1;i<=m;i++){ for(int j=mmax-v[i];j>=0;j--){ dp[l][j]=max(dp[l][j],dp[l][j+v[i]]+w[i]); } } } //最后一天状态更新 int ans=0; for(int i=0;i<=mmax;i++){ ans=max(ans,dp[n][i]+i+f[i]); } cout<<ans<<endl; }