度度熊与邪恶大魔王Accepts: 3666 Submissions: 22474
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
度度熊为了拯救可爱的公主,于是与邪恶大魔王战斗起来。 邪恶大魔王的麾下有n个怪兽,每个怪兽有a[i]的生命值,以及b[i]的防御力。 度度熊一共拥有m种攻击方式,第i种攻击方式,需要消耗k[i]的晶石,造成p[i]点伤害。 当然,如果度度熊使用第i个技能打在第j个怪兽上面的话,会使得第j个怪兽的生命值减少p[i]-b[j],当然如果伤害小于防御,那么攻击就不会奏效。 如果怪兽的生命值降为0或以下,那么怪兽就会被消灭。 当然每个技能都可以使用无限次。 请问度度熊最少携带多少晶石,就可以消灭所有的怪兽。
Input
本题包含若干组测试数据。 第一行两个整数n,m,表示有n个怪兽,m种技能。 接下来n行,每行两个整数,a[i],b[i],分别表示怪兽的生命值和防御力。 再接下来m行,每行两个整数k[i]和p[i],分别表示技能的消耗晶石数目和技能的伤害值。 数据范围: 1<=n<=100000 1<=m<=1000 1<=a[i]<=1000 0<=b[i]<=10 0<=k[i]<=100000 0<=p[i]<=1000
Output
对于每组测试数据,输出最小的晶石消耗数量,如果不能击败所有的怪兽,输出-1
Sample Input
Copy
1 2
3 5
7 10
6 8
1 2
3 5
10 7
8 6
Sample Output
Copy
6
18
#include "iostream"
#include "fstream"
#include "vector"
#include "string.h"
using namespace std;
typedef long long LL;
struct Monster
{
LL a, b;
};
struct Attact
{
LL k, p;
};
LL min(LL a, LL b)
{
return a < b ? a : b;
}
LL max(LL a, LL b)
{
return a > b ? a : b;
}
int main()
{
int n, m;
Monster monster[100001];
Attact attact[1001];
while(cin >> n >> m)
{
int i, j, k;
LL max1 = 0, max2 = 0, max3 = 0;
for(i=0; i<n; i++)
{
cin >> monster[i].a >> monster[i].b;
max1 = max(monster[i].b, max1);
max3 = max(monster[i].a, max3);
}
for(i=0; i<m; i++)
{
cin >> attact[i].k >> attact[i].p;
max2 = max(attact[i].p, max2);
}
if(max2 <= max1) // 最大的伤害<=最大的防御
{
cout << -1 << endl;
continue;
}
LL dp[1001][11];
memset(dp, 0, sizeof(dp));
for(j=0; j<=10; j++) // 防御
{
for(i=1; i<=max3; i++) // 生命值
{
dp[i][j] = 100000000LL;
for(k=0; k<m; k++) // 技能
{
int hurt = attact[k].p - j;
if(hurt > 0)
{
if(hurt >= i)
dp[i][j] = min(dp[i][j], attact[k].k);
else
dp[i][j] = min(dp[i][j], dp[i-hurt][j] + attact[k].k);
}
}
}
}
LL cost = 0LL;
for(i=0; i<n; i++)
{
cost += dp[ monster[i].a ][ monster[i].b ];
}
cout << cost << endl;
}
//getchar();
//getchar();
return 0;
}