Topic links
- Test instructions
n 1*1 in the horizontal direction, each lattice can grow a plant, passing a lattice time is t. Altogether three kinds of plants: R plants. R point damage received per second after passing, G plant, G-point damage per second after passing, b plant, after passing through a lattice time plus B
2<=n<=1500,0<=r, G, b<=60000,1<=t<=3
- Analysis:
The most beginning to consider the greedy: first b plants, after g plants, finally B plants. Later found to be wrong.
First, it is clear that r plants have no effect on the location of the answer, whereas B and G plants grow better early, so the problem lies in the methods of B and G.
The status is expressed to be clear, regardless of the position of G and B. The subsequent situation is only related to the number of B and G. So can DP. DP[I][J] indicates that the total damage of the plant is now a b plant, J G. can be greedy. Implementation of one-dimensional DP processing
LL N, G, B, r, T; LL Dp[maxn];int Main () {int T; RI (T); FE (Kase, 1, T) {cin >> n >> R >> G >> b >> T; LL ans = n * r * t; CLR (DP,-1); Dp[0] = 0; REP (all, N) {FED (i, n, 0) {if (~dp[i]) {L L NXT = Dp[i] + (i * b + t) * (all-i) * g; if (Dp[i + 1] < NXT) Dp[i + 1] = NXT; NXT = Dp[i] + (i * b + t) * (all-i) * g; if (Dp[i] < NXT) Dp[i] = NXT; }} FE (i, 0, N) {if (~dp[i]) {LL NXT = Dp[i] + (N-ALL-1) * (t + i * b) * (R + (all + 1-i) * g); if (ans < nxt) ans = nxt; }}} printf ("Case #%d:%i64d\n", Kase, ans); } return 0;}
Stupid Tower Defense