HDU 4939 - Stupid Tower Defense (DP)

39 篇文章 0 订阅

Stupid Tower Defense

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 537    Accepted Submission(s): 143



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:   4944  4943  4942  4941  4940 
 

Statistic |  Submit |  Discuss |  Note



题意:

长为n个单位的直线,通过一个单位长度时间为t,在每个单元格子里面可以建红绿蓝三种塔

红塔:造成当前格子每秒x点伤害

绿塔:造成通过这个格子后的所有格子(不包括当前格子)每秒y点伤害

蓝塔:造成通过这个格子后的所有格子(不包括当前格子)单位格子通过时间加z秒

问如何使得从1走到n的伤害最大



很明显所有红塔肯定放在最后面,如果一个红塔在绿塔或者蓝塔前面,那么交换两个塔后,伤害值肯定会增加。

剩下的就是前面的绿塔和蓝塔如何放置了,之前考虑DP的时候,考虑到有t(通过单位格子的时间)和v(每秒伤害值)会影响当前状态,但是t v都太大了,然后考虑贪心,考虑绿塔都在前面,中间是蓝塔,后来经过计算发现这样不行,然后突然发现现在只有绿塔和蓝塔,而且n<=1500,如果有dp[i][j]表示前i个放置了j个绿塔得到的最大伤害值,那么tv都可以通过ij算出来,就不用tv来表示状态了,然后一高兴就开始写。。。


后来发现我是一个傻逼

想到一点思路就开始写 这题一些边界和计算多一些 自己代码精度又奇低 导致无限WA 赛后都调了好久 

现在状态又这么差。。。

我真是猪 希望能够记住这次的教训吧



#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;

#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#define oform1 "%I64d"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#define oform1 "%lld"
#endif

#define S64I(a) scanf(iform, &(a))
#define P64I(a) printf(oform, (a))
#define P64I1(a) printf(oform1, (a))
#define REP(i, n) for(int (i)=0; (i)<n; (i)++)
#define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++)

const int INF = 0x3f3f3f3f;
const double eps = 10e-9;
const double PI = (4.0*atan(1.0));

const int maxn = 1500 + 20;
LL dp[maxn][maxn];

int main() {
    int T;

    scanf("%d", &T);
    for(int kase=1; kase<=T; kase++) {
        int _n, _x, _y, _z, _t;
        scanf("%d%d%d%d%d", &_n, &_x, &_y, &_z, &_t);
        LL n = _n, x = _x, y = _y, z = _z, t = _t;
        LL ans = x*t*n; //!
        for(LL i=1; i<=n; i++) {
            for(LL j=0; j<=i; j++) {
                if(j == 0) {
                    dp[i][j] = 0;
                    LL tans = (LL)(n-i) * (t+(LL)i*z) * x;
                    ans = max(tans, ans);
                    continue;
                }
                //LL tt = t + (i-j) * z;
                //LL tv = (LL) y * (j-1);
                LL tg = dp[i-1][j-1] + (j-1)*y*(t+(i-j)*z);
                //tt = t + (i - 1 -j) * z;
                //tv = y * j;
                LL tb = dp[i-1][j] + j*y*(t+(i-1-j)*z);
                if(i-1 < j) tb = 0;
                dp[i][j] = max(tg, tb);
                //tt = t + (i-j) * z;
                LL tans = dp[i][j] + (n-i)*(j*y+x)*(t+(i-j)*z);
                ans = max(ans, tans);
            }
        }
        printf("Case #%d: ", kase);
        P64I(ans);
    }

    return 0;
}









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值