Time Limit: 1000 MS Memory Limit: 131072 K
Description
Kaiwen is an excellent student who loves studying
The final exam is approaching in N hours, and now he starts to prepare for his 《Computer network》 exam
《Computer network》 has M chapters
Kaiwen can get vi points if he has studyed the chapter i
Studying the chapter i needs ti hours
Obviously N hours is not enough to study all chapters for Kaiwen
So the question is how many points can Kaiwen get at most?
Input
The first line is an integer T standing for the number of test cases.
Then T test cases follow.
For each case
The first line has two integers N and M
then M lines follow, every line has two integers v and t represent vi and ti
(1≤N,M,v,t≤200)
Output
For each case, output the maximum point Kaiwen can get
Sample Input
1
8 5
5 3
2 10
2 6
3 8
5 14
Sample Output
24
注释:01背包,没什么可讲的
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int N,M;
int v,t;
int sum[209];
memset(sum,0,sizeof(sum));
scanf("%d%d",&N,&M);
for(int i=1;i<=M;i++)
{ scanf("%d%d",&v,&t);
for(int j=N; j>=v; j--)
{
if(sum[j-v]+t>sum[j])
sum[j]=sum[j-v]+t;
}
}
printf("%d\n",sum[N]);
}
return 0;
}