Link: HDU 4939 stupid tower defense
Theme: tower guard game, a road with a length of N, given X, Y, Z and T. Then, the attack tower can be placed at each length. There are three types:
- Red Tower: X points per second damage to the red tower within the unit length.
- Green Tower: After the monster passes through the Green Tower, it is hurt by point y every second.
- Blue Tower: Add Z to the time each passing by a grid.
Maximum damage.
Solution: The redtower must be placed at the end of the topic. Therefore, DP [I] [J] indicates the position I, the maximum damage caused by J blue towers. And maintain the largest ans (add the Red Tower attack damage) during the process. For a status DP [I] [J], in addition to transferring to DP [I + 1] [J] and DP [I + 1] [J + 1], you can regard the n-I positions below as the redtower, to maintain ans.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef unsigned long long ll;const int maxn = 1505;int N;ll x, y, z, T;ll dp[maxn][maxn];ll solve () { ll ans = 0; memset(dp, 0, sizeof(dp)); for (int i = 0; i < N; i++) { for (int j = 0; j <= i; j++) { ll v = (T + j * z); ll w = v * (i-j) * y; dp[i+1][j] = max(dp[i+1][j], dp[i][j] + w); dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + w); ans = max(ans, dp[i][j] + (x * v + w) * (N-i)); } } for (int i = 0; i <= N; i++) ans = max(ans, dp[N][i]); return ans;}int main () { int cas; scanf("%d", &cas); for (int kcas = 1; kcas <= cas; kcas++) { scanf("%d%I64u%I64u%I64u%I64u", &N, &x, &y, &z, &T); // scanf("%d%lld%lld%lld%lld", &N, &x, &y, &z, &T); // printf("Case #%d: %lld\n", kcas, solve()); printf("Case #%d: %I64u\n", kcas, solve()); } return 0;}