Topic ideas:
Obviously dp problem is the number of days as a stage, and then set inside a backpack full, as it will get the node at the end of every day, so the number of days in the last cycle but also add a loop to add nodes obtained at the end of each day.
dp [u] represents now finally able to get the number of nodes when a node u, there are several places to note, first of all there is the current number of nodes from the 2000 cycle , as w [i] and the range of k is 1000, If you say that currently there are 1000 nodes, the nodes also received 1000, so there may be up to 2000 nodes (node k get is greater than 0). Followed by the final plus to take a maximum number of nodes you get every day. Finally, remember to add the current answer some nodes.
Code:
#include<bits/stdc++.h> using namespace std; int dp[10010],w[10010],n,m,k,ans; pair<int,int>p[101];//代表题目中的ai,bi int main() { memset(dp,128,sizeof(dp)); scanf("%d%d%d",&n,&m,&k); for(int i = 0;i<=k;i++) scanf("%d",&w[i]); for(int i = 1;i<=m;i++) scanf("%d%d",&p[i].first,&p[i].second); dp[0] = 0; for(int i = 1;i<=n;i++)//天数 { for(int j = 1;j<=m;j++)//存储方式 for(int u = 2000;u>=0;u--)//当前有的节点数 dp[u] = max(dp[u],dp[u+p[j].first]+P [J] .second); for ( int U = 2000 ; U> = 0 ; u - the) // plus the number of nodes obtained at the end of the day DP [W U + [U]] = max (DP [U + W [U]], DP [U]); } for ( int I = 0 ; I <= 2000 ; I ++ ) ANS = max (ANS, DP [I] + I); // node plus the final answer equal to the last obtained some of the current node on the printf ( " % D " , ANS); return 0 ; }