标签:des style blog http color java os io
Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1219    Accepted Submission(s): 361
Mean:
经典的塔防类游戏。
敌人要通过一条过道,你有三种塔:红塔---敌人经过该塔时每秒受到x点伤害; 绿塔---敌人经过该塔后,每秒受到y点伤害; 蓝塔---敌人经过该塔后,经过每座塔的时间变慢z秒。现在要你安排这三种塔,使得对敌人的伤害最大。
analyse:
分析可知,红塔要放到后面。
然后我们枚举红塔的数量i,对前n-i座塔进行dp。
dp[i][j]----表示前i座塔中,放j座蓝塔和i-j座绿塔所造成的最大伤害。
x y z t
状态转移方程:
dp[i][j]=max(dp[i-1][j-1]+y*(i-j)*(t+(j-1)*z),dp[i-1][j]+(i-1-j)*y*(t+j*z))
。
Time complexity:O(n^2)
Source code:
//Memory   Time
// 18424K   1796MS
// by : Snarl_jsb
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<cmath>
#define MAX 1520
#define LL long long
using namespace std;
LL dp[MAX][MAX];
int main()
{
    LL T,kase=1;
    cin>>T;
    while(T--)
    {
        LL n,x,y,z,t,damage;
        scanf("%I64d %I64d %I64d %I64d %I64d",&n,&x,&y,&z,&t);
        printf("Case #%I64d: ",kase++);
        memset(dp,0,sizeof(dp));
        dp[1][1]=x;
        LL ans=n*x*t;                  //全部放红塔的伤害值
        for(LL i=1;i<=n;i++)          //枚举前i个单位长度
        {
            for(LL j=0;j<=i;j++)     // 枚举前i个单位中蓝塔的数量j
            {
                if(j==0)
                    dp[i][j]=dp[i-1][j]+y*(i-1)*t;
                else
                {
                    LL tmp1=dp[i-1][j-1]+y*(i-j)*(t+z*(j-1));  // 第j座放蓝塔
                    LL tmp2=dp[i-1][j]+y*(i-1-j)*(t+z*j);       // 第j座放绿塔
                    dp[i][j]=max(tmp1,tmp2);
                }
                damage=dp[i][j]+(n-i)*x*(t+z*j)+(n-i)*(i-j)*y*(t+z*j);
                ans=max(ans,damage);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
dp --- hdu 4939 : Stupid Tower Defense,布布扣,bubuko.com
dp --- hdu 4939 : Stupid Tower Defense
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/acmer-jsb/p/3911872.html