HDU 4939 Stupid Tower Defense dp
Posted blfbuaa
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 4939 Stupid Tower Defense dp相关的知识,希望对你有一定的参考价值。
由于瞬间伤害的塔一定是放在终点端的,所以枚举这样的塔的个数
然后就能把n^3变成n^2了
#include <cstdio> #include <cstring> #include <algorithm> typedef long long ll; const int N = 1500 + 2; ll d[N][N]; // j = 3; int Tt = 0, n, x, y, z, t; inline void up(ll& a, ll v) { if (v > a) a = v; } void work() { ll ans = 0, T, D; scanf("%d%d%d%d%d", &n, &x, &y, &z, &t); for (int i = 0; i <= n; ++i) for (int j = 0; j <= i; ++j) d[i][j] = 0; for (int i = 0; i < n; ++i) for (int j = 0; j <= i; ++j) { T = t + (ll)z * j; D = T * (n - i) * x + T * (n - i) * y * (i - j) + d[i][j]; up(ans, D); // put a 2 up(d[i + 1][j], d[i][j] + (ll)(i - j) * y * T); up(d[i + 1][j + 1], d[i][j] + (ll)(i - j) * y * T); } for (int i = 0; i <= n; ++i) up(ans, d[n][i]); printf("Case #%d: %I64d\n", ++Tt, ans); } int main() { int cas; scanf("%d", &cas); while (cas -- > 0) work(); return 0; }
以上是关于HDU 4939 Stupid Tower Defense dp的主要内容,如果未能解决你的问题,请参考以下文章
hdu 4779 Tower Defense (思维+组合数学)