Stupid Tower Defense
Problem Description
FSF is addicted to a stupid tower defense game. The goal of tower defense games is to try to stop enemies from crossing a map by building traps to slow them down and towers which shoot at them as they pass.
The map is a line, which has n unit length. We can build only one tower on each unit length. The enemy takes t seconds on each unit length. And there are 3 kinds of tower in this game: The red tower, the green tower and the blue tower.
The red tower damage on the enemy x points per second when he passes through the tower.
The green tower damage on the enemy y points per second after he passes through the tower.
The blue tower let the enemy go slower than before (that is, the enemy takes more z second to pass an unit length, also, after he passes through the tower.)
Of course, if you are already pass through m green towers, you should have got m*y damage per second. The same, if you are already pass through k blue towers, the enemy should have took t + k*z seconds every unit length.
FSF now wants to know the maximum damage the enemy can get.
The map is a line, which has n unit length. We can build only one tower on each unit length. The enemy takes t seconds on each unit length. And there are 3 kinds of tower in this game: The red tower, the green tower and the blue tower.
The red tower damage on the enemy x points per second when he passes through the tower.
The green tower damage on the enemy y points per second after he passes through the tower.
The blue tower let the enemy go slower than before (that is, the enemy takes more z second to pass an unit length, also, after he passes through the tower.)
Of course, if you are already pass through m green towers, you should have got m*y damage per second. The same, if you are already pass through k blue towers, the enemy should have took t + k*z seconds every unit length.
FSF now wants to know the maximum damage the enemy can get.
Input
There are multiply test cases.
The first line contains an integer T (T<=100), indicates the number of cases.
Each test only contain 5 integers n, x, y, z, t (2<=n<=1500,0<=x, y, z<=60000,1<=t<=3)
The first line contains an integer T (T<=100), indicates the number of cases.
Each test only contain 5 integers n, x, y, z, t (2<=n<=1500,0<=x, y, z<=60000,1<=t<=3)
Output
For each case, you should output "Case #C: " first, where C indicates the case number and counts from 1. Then output the answer. For each test only one line which have one integer, the answer to this question.
Sample Input
1 2 4 3 2 1
Sample Output
Case #1: 12
题意: 给出3种塔防装置,有红塔(只经过的时候掉分),绿塔(经过之后每秒都掉分),兰塔 (能延缓怪物的行进速度)。 问如何安置塔防恩能使得
怪物掉分最多。
sl : 刚开始题意理解错了逗比了一个小时,后来知道, t + k*z 是固定的。 这就是傻逼的dp了。
dp[i][j]=max(dp[i-1][j-1]+(t+(j-1)*z)*y*(i-j),dp[i-1][j]+(t+j*z)*y*(i-j-1));
i表示当前是第i个位置。 j表示前面有多少个兰塔。因为红塔放在最后面肯定就是最优的(显而易见)。
1 // by caonima
2 // hehe
3 #include <cstdio>
4 #include <cstring>
5 #include <algorithm>
6 #include <vector>
7 #include <map>
8 using namespace std;
9 typedef long long LL;
10 const int MAX= 2000+10;
11 const LL inf = 1LL<<15;
12 LL n,x,y,z,t;
13 LL dp[MAX][MAX];
14 LL gao() {
15 for(LL i=1;i<=n;i++) {
16 for(LL j=0;j<=i;j++) {
17 if(j>0) dp[i][j]=dp[i-1][j-1]+(t+(j-1)*z)*y*(i-j);
18 dp[i][j]=max(dp[i][j],dp[i-1][j]+(t+j*z)*y*(i-j-1));
19 }
20 }
21 LL ans=-inf;
22 for(LL i=1;i<=n;i++) {
23 for(LL j=0;j<=i;j++) { // blue tower
24 ans=max(ans,dp[i][j]+(n-i)*x*(t+j*z)+(n-i)*(i-j)*(t+j*z)*y);
25 }
26 }
27 ans=max(ans,n*x*t);
28 return ans;
29 }
30 int main() {
31 int cas,cnt=0;
32 scanf("%d",&cas);
33 while(cas--) {
34
35 scanf("%I64d %I64d %I64d %I64d %I64d",&n,&x,&y,&z,&t);
36 memset(dp,0,sizeof(dp));
37 LL ans=gao();
38 printf("Case #%d: %I64d ",++cnt,ans);
39 }
40 }
41
42 /*
43 3
44 3 20 100 5 1
45
2 // hehe
3 #include <cstdio>
4 #include <cstring>
5 #include <algorithm>
6 #include <vector>
7 #include <map>
8 using namespace std;
9 typedef long long LL;
10 const int MAX= 2000+10;
11 const LL inf = 1LL<<15;
12 LL n,x,y,z,t;
13 LL dp[MAX][MAX];
14 LL gao() {
15 for(LL i=1;i<=n;i++) {
16 for(LL j=0;j<=i;j++) {
17 if(j>0) dp[i][j]=dp[i-1][j-1]+(t+(j-1)*z)*y*(i-j);
18 dp[i][j]=max(dp[i][j],dp[i-1][j]+(t+j*z)*y*(i-j-1));
19 }
20 }
21 LL ans=-inf;
22 for(LL i=1;i<=n;i++) {
23 for(LL j=0;j<=i;j++) { // blue tower
24 ans=max(ans,dp[i][j]+(n-i)*x*(t+j*z)+(n-i)*(i-j)*(t+j*z)*y);
25 }
26 }
27 ans=max(ans,n*x*t);
28 return ans;
29 }
30 int main() {
31 int cas,cnt=0;
32 scanf("%d",&cas);
33 while(cas--) {
34
35 scanf("%I64d %I64d %I64d %I64d %I64d",&n,&x,&y,&z,&t);
36 memset(dp,0,sizeof(dp));
37 LL ans=gao();
38 printf("Case #%d: %I64d ",++cnt,ans);
39 }
40 }
41
42 /*
43 3
44 3 20 100 5 1
45
46 */