HDOJ 6082 度度熊与邪恶大魔王

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6082



百度之星2017资格赛的第三题。

自从从集训队退出之后,就再也没有做过题目了,当天晚上突然看到短信才想起还参加了这个比赛,当时正在看守望世界杯(堕落的暑假),有点心急,尤其是当时点开第一题看了一下,满脑子都是这TMD能做,未免有点心烦,心想反正做一题就可以了,于是马上打开了过题人数最多的一题,也就是这题。

这题思路和题意都很简单,每个技能都有晶石消耗和攻击力,每个怪都有HP和防御力,怎么才能在晶石消耗最小的情况下打掉所有的怪。思路也是很容易的DP解决,区别就是因为每个怪的防御力不同所以要做n次DP。

#include <cstdio>
#include <cstring>  
#include <iostream>
#include <algorithm>  
using namespace std;  
typedef long long LL;
const LL INF = 1e18;  
const int maxn = 2005;  
const int maxm = 1e5 + 100;  
inline LL input() 
{  
    LL res = 0, ch, flag = 0;  
    if((ch=getchar())=='-') {
    	flag = 1;
	}  
    else if(ch>='0' && ch<='9') {
    	res=ch-'0';
	} 
    while((ch=getchar())>='0'&&ch<='9') {
    	res = res*10+ch-'0';
	}
    return flag? -res : res;  
}  
LL dp[maxn][15];
LL a[maxm],b[maxm],k[maxn],p[maxn];  
int main()  
{
    int n,m;  
    while(scanf("%d%d", &n, &m) !=EOF)  
    {  
        for(int i=0; i<n; i++)  
        {  
            a[i] = input();
			b[i] = input();  
        }  
        for(int i=0; i<m; i++)  
        {  
            k[i] = input();
			p[i] = input();  
        }  
        for(int i=0; i<maxn; i++) {
        	for(int j=0; j<=10; j++) {
        		dp[i][j] = INF;
			}
		}
        for(int i=0; i<=10; i++)
        {  
            dp[0][i] = 0;  
            for(int j=0; j<m; j++)  
            {  
                LL tmp = p[j]-i; 
                if(tmp <= 0) continue;  
                for(int x=tmp; x<=2003; x++)  
                {  
                    dp[x][i]=min(dp[x - tmp][i] + k[j], dp[x][i]);  
                }  
            }  
            for(int j=2002; j>=0; j--) 
            {  
                dp[j][i] = min(dp[j][i], dp[j+1][i]);  
            }  
        }  
        LL ans=0;  
        for(int i=0; i<n; i++) {
        	ans += dp[a[i]][b[i]];
		}
        if(ans >= INF) {
        	printf("-1\n");  
		}
        else cout << ans << endl;  
    }  
} 


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值