码迷,mamicode.com
首页 > 其他好文 > 详细

HLG 哈理工 1053 Warcraft III (完全背包)

时间:2015-08-29 11:13:59      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:acm   算法   编程   哈理工   dp   

Warcraft III
Time Limit: 10000 MS Memory Limit: 65536 K
Total Submit: 587(194 users) Total Accepted: 260(173 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

Author

dccmx


/*=============================================================================
#
#      Author: liangshu - cbam 
#
#      QQ : 756029571 
#
#      School : 哈尔滨理工大学 
#
#      Last modified: 2015-08-29 00:24
#
#     Filename: C.cpp
#
#     Description: 
#        The people who are crazy enough to think they can change the world, are the ones who do ! 
=============================================================================*/
#
#include<stdio.h>
#include<iostream>
using namespace std;

const int INF = 100000;
int dp[INF];
struct A
{
    int val,cost;
}E[INF];
int main(){
    int T;
    cin>>T;
    while(T--){
        int G, U;scanf("%d%d",&G, &U);
        memset(dp, 0, sizeof(dp));
        for(int i = 1; i <= U; i++){
            scanf("%d%d",&E[i].val, &E[i].cost);
        }
        for(int i = 1; i <= U; i++){
            for(int j = E[i].cost; j <= G; j++){
                dp[j] = max(dp[j], dp[j - E[i].cost] + E[i].val);
            }
        }
     printf("%d\n",dp[G]);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

HLG 哈理工 1053 Warcraft III (完全背包)

标签:acm   算法   编程   哈理工   dp   

原文地址:http://blog.csdn.net/lsgqjh/article/details/48065833

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!