HDU-4939 Stupid Tower Defense

1 篇文章 0 订阅

题目链接Stupid Tower Defense

题目大意:一条长度为n的道路,有敌人从道路右端袭来,敌人有自己的速度,你的任务是尽可能多得使敌人受到伤害。红塔是直接每秒造成x点伤害,绿塔是经过它之后每秒造成y点伤害(可叠加),蓝塔是经过它之后每走一个单位的道路需要增加z秒(可叠加)。

解题思路:直接DP的话会超时,于是我们用一个贪心的思路来做这道题,如果在前面的道路放蓝塔或绿塔(或全部不放),后面全部放红塔的话收益一定是最大的。稍微要注意的是蓝塔和绿塔不放的情况。

代码如下:

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf  = 0x3f3f3f3f;
const int maxn = 2e4 + 15;

ll dp[1505][1505];

int main(){
#ifdef NEKO
    freopen("Nya.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);  cin.tie(0);
    int t, kase = 1; cin >> t;
    while(t--){
        ll n, x, y, z, t;
        cin >> n >> x >> y >> z >> t;
        ll ans = 0;
        ans = x * n * t;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= i; j++){                
                ll res = 0;
                if(j > 0 && i - j >= 0) 
                    res = max(res, dp[j - 1][i - j] + y * (j - 1) * (t + (i - j) * z));
                if(i - j - 1 >= 0) 
                    res = max(res, dp[j][i - j - 1] + y * j * (t + (i - j - 1) * z));
                dp[j][i - j] = res;
                ans = max(ans, res + (y * j + x) * (t + (i - j) * z) * (n - i));
            }
        }
        cout << "Case #" << kase++ << ": " << ans << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值