HLG 1053 Warcraft III(背包DP)

Warcraft III

点击打开题目链接

Time Limit: 10000 MSMemory Limit: 65536 K
Total Submit: 458(136 users)Total Accepted: 181(120 users)Rating:Special Judge: No
Description

dccmx likes playing Warcraft III. Now, he is teaching his girlfriend to play it. In Warcraft III, there are many kinds of units. Every unit costs some gold and lumber. Different units have different attack value.

Now question comes. Given some amount of gold and a list of types of units, how to arrange your units to maximize the attack value of your units. Assume you have infinite lumbers.

Input

Line 1 contains an integer T: the number of test cases.

Next T blocks, each starts with two integers: G and U, represents the amount of gold and number of unit type. Next U lines, each contains two integers: the attack value of a type of unit and the cost.

Output

For each test case, output the maximum total attack value in one line.

Sample Input

2

100 1

20 10

300 4

100 60

250 120

120 100

35 20

Sample Output

200

605


裸的完全背包问题;

代码:

#include <iostream>
#include<string.h>
#include<stdio.h>
#define N 10000
#define max(a,b) a>b?a:b
using namespace std;
int main()
{
    int t;
    int value[N],dp[N],v[N],V,n,i,j;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            memset(dp,0,sizeof(dp));
            scanf("%d%d",&V,&n);
            for(i=0;i<n;i++)
            {
                scanf("%d%d",&value[i],&v[i]);
            }
            for(i=0;i<n;i++)
            {
                for(j=v[i];j<=V;j++)
                {
                    dp[j]=max(dp[j],dp[j-v[i]]+value[i]);
                }
            }
            cout<<dp[V]<<endl;
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值