标签:个数 string for cst std type int ack algorithm
由于瞬间伤害的塔一定是放在终点端的,所以枚举这样的塔的个数
然后就能把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
标签:个数 string for cst std type int ack algorithm
原文地址:http://www.cnblogs.com/blfbuaa/p/6905690.html