Stupid Tower Defense

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1986    Accepted Submission(s): 545

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.

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)

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
Hint
For the first sample, the first tower is blue tower, and the second is red tower. So, the total damage is 4*(1+2)=12 damage points.

Author
UESTC

Source

Recommend
We have carefully selected several similar problems for you:  5566 5565 5564 5563 5562

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<cctype>
#include<utility>
#define PI (4.0*atan(1.0))
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n)  for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n)  for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n)  for(int i=(n) ;i>=0 ;i--)
#define  lson   ind<<1,le,mid
#define rson    ind<<1|1,mid+1,ri
#define MID   int mid=(le+ri)>>1
#define zero(x)((x>0? x:-x)<1e-15)
#define mk    make_pair
#define _f     first
#define _s     second
using namespace std;
//const int INF=    ;
typedef long long ll;
//const ll inf =1000000000000000;//1e15;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
const int INF =0x3f3f3f3f;
const int maxn= 1500+20   ;
//const int maxm=    ;
ll n,x,y,z,t;
ll maxi,dp[maxn][maxn];//dp[i][j]表示前面放了i个塔，其中有j个蓝塔。

int main()
{
int T,kase=0;scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld%lld%lld",&n,&x,&y,&z,&t);
maxi=t*n*x;
//注意状态的表示，以及对于任意一种方法 红塔应该放在最后。
//但没想到红塔的伤害可以在O(1)时间内算出。
//就是枚举i和j然后可以求出红塔的伤害。这里用了“红塔应该放在最后”；
for(int i=1;i<=n;i++)
{
for(int j=0;j<=i;j++)
{
if(!j)   dp[i][j]=dp[i-1][j]+ t*(i-1)*y ;   //此步放绿塔
else  dp[i][j]=max(dp[i-1][j]  + (t+           j*z) *max(0,(i-j-1))*y,//绿
dp[i-1][j-1]+ (t+ max(0,j-1 )*z) *(i-j)*y     );//蓝

maxi=max(maxi, dp[i][j]+(t+j*z)* (n-i)*(x+ (i-j)*y    )  );//之后放红塔
}

}
printf("Case #%d: %lld\n",++kase,maxi);
}

return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：hdu 4939 Stupid Tower Defense dp 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)