题目链接: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;
}