南邮 OJ 1443 Warcraft III

Warcraft III

时间限制(普通/Java) :  2000 MS/ 6000 MS          运行内存限制 : 65536 KByte
总提交 : 142            测试通过 : 49 

比赛描述

John 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.




输入

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: attack value of a type of unit and the cost.


输出

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


样例输入

2
100 1
20 10
300 4
100 60
250 120
120 100
35 20

样例输出

200
605

题目来源

NUPT ACM 2010 Personal Ranking Contest



#include<stdio.h>
#define N 10000
int unit[N];
int cost[N];
int maxAttack[N];

int main(){
	int T,G,U,i,j;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&G,&U);
		for(i=1; i<=G; i++){
			maxAttack[i] = 0;
		}
		while(U--){
			scanf("%d%d",&i,&j);
			maxAttack[j] = i;
		}
		for(i=1; i<=G; i++){
			for(j=1; j*2<=i; j++){
				if(maxAttack[i] < maxAttack[j]+maxAttack[i-j]){
					maxAttack[i] = maxAttack[j]+maxAttack[i-j];
				}
			}
		}
		printf("%d\n",maxAttack[G]);
	}
}






你可能感兴趣的:(ACM,III,Warcraft,南邮OJ)