2016huasacm暑假集训训练五 G - 湫湫系列故事——减肥记I

题目链接:https://vjudge.net/contest/126708#problem/G

这是一个01背包的模板题

AC代码:

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[];
struct Node
{
int xishouliang;
int xingfuzhi;
} a[];
int main()
{
int i, j, t, m;
while(~scanf("%d", &t))
{
memset(dp,,sizeof(dp));
for (i = ; i <= t; i++)
scanf("%d%d", &a[i].xingfuzhi, &a[i].xishouliang);
scanf("%d",&m);
for (i = ; i <= t; i++)
{
for (j = a[i].xishouliang; j <= m; j++)
{
dp[j] = max(dp[j], dp[j - a[i].xishouliang] + a[i].xingfuzhi);
}
}
printf("%d\n", dp[m]);
}
return ;
}
上一篇:nohup & expect & netstat学习


下一篇:box-shadow IE8兼容处理