Easy Problem V

SCU-4485

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值