标签:image info ima 技术分享 style span nbsp can main
采用一维数组进行优化
#include<cstdio>
#include<algorithm>
using namespace std;
int w[105], v[105];
int dp[1005];
int main()
{
int m, n;
scanf("%d%d", &m, &n);
for(int i=1; i<=n; i++)
scanf("%d%d", &w[i], &v[i]);
for(int i=1; i<=n; i++)
for(int j=m; j>=w[i]; j--)
dp[j]=max(dp[j], dp[j- w[i]]+v[i]);
printf("%d", dp[m]);
}
标签:image info ima 技术分享 style span nbsp can main
原文地址:https://www.cnblogs.com/dongdong25800/p/9892462.html