#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背包问题)
最新推荐文章于 2023-04-26 08:50:26 发布