#include <stdio.h>
#include <string.h>typedef struct Thing
{
int time, value;
}Ting;Ting thing[11];
int max(int a, int b)
{
return a > b ? a:b;
}int dp[1001];
int main()
{
int t, m;
scanf("%d %d", &t, &m);
for(int i = 1; i <= m; i++)
scanf("%d %d", &thing[i].time, &thing[i].value);
memset(dp, 0, 1001); //头文件为string.h或者memory.h
for(int i = 1; i <= m; i++)
for(int j = t; j >= thing[i].time; j--)
dp[j] = max(dp[j-thing[i].time] + thing[i].value, dp[j]);
printf("%d\n", dp[t]);
return 0;
}
采药 OpenJ_Bailian - 2726(0-1背包问题)
猜你喜欢
转载自blog.csdn.net/mch2869253130/article/details/85596110
今日推荐
周排行