zoukankan      html  css  js  c++  java
  • hdu 4939 三色塔防

    http://acm.hdu.edu.cn/showproblem.php?pid=4939

    给出一条长为n个单位长度的直线,每通过一个单位长度需要 t 秒。
    有3种塔,红塔可以在当前格子每秒造成 x 点伤害,绿塔可以在之后的格子每秒造成 y 点伤害,蓝塔可以使通过单位长度的时间增加 z 秒。(if you are already pass through k blue towers, the enemy should have took t + k*z seconds every unit length.)问如何安排3种塔的顺序使得造成的伤害最大,输出最大伤害值。

    显然红塔在前面没有在后面造成的伤害大,那么只剩下蓝塔和绿塔的分配,考虑使用dp

    dp[i][j]表示前 i + j 格种了i个绿塔j个蓝塔,那么转移方程就可以写出了,再种一个蓝塔多出的伤害是i * y * (t + (j - 1) * z) , 多种一个绿塔多出的伤害是(i - 1) * y * (t + j * z)

    dp[i][j] = max(dp[i - 1][j] + (i - 1) * y * (t + j * z) , dp[i][j - 1] + i * y * (t + (j - 1) * z));

    剩下的就是红塔,那么答案就是max( dp[i][j] + (x + (i * y)) * (n - i - j) * (t + j * z) )

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <queue>
    #include <vector>
    #include<set>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define RD(x) scanf("%d",&x)
    #define RD2(x,y) scanf("%d%d",&x,&y)
    #define clr0(x) memset(x,0,sizeof(x))
    typedef long long LL;
    LL f[2005][2005];
    int main()
    {
        int _;RD(_);
        for(int tt = 1;tt <= _;++tt){
            int n,x,y,z,t;
            scanf("%d%d%d%d%d",&n,&x,&y,&z,&t);
            clr0(f);LL ans = 0;
            for(int i = 0;i <= n;i++){
                for(int j = 0;j + i <= n;j++){
                    if (i)
                        f[i][j] = max(f[i][j], f[i - 1][j] + 1LL * (i - 1) * y * (t + j * z));
                    if (j)
                        f[i][j] = max(f[i][j], f[i][j - 1] + 1LL * i * y * (t + (j - 1) * z));
                    LL rest = 1LL * (x + (i * y)) * (n - i - j) * (t + j * z);
                    ans = max(ans, rest + f[i][j]);
                }
            }
            printf("Case #%d: %I64d
    ",tt,ans);
        }
        return 0;
    }


  • 相关阅读:
    xml在html中的使用
    getElementsByTagName的用法
    opener 的使用
    动态增加属性
    innerText, innerHTML,outerHTML
    button的css属性
    动态改变select中option的次序
    input 的样式
    zkw线段树
    接着吐槽(2012/5/23)
  • 原文地址:https://www.cnblogs.com/zibaohun/p/4046802.html
Copyright © 2011-2022 走看看