hdu 4939 Stupid Tower Defense(dp),hdu4939

來源:互聯網
上載者:User

hdu 4939 Stupid Tower Defense(dp),hdu4939

題目連結:hdu 4939 Stupid Tower Defense

題目大意:塔防遊戲,一個長度為n的路,給定x,y,z和t。然後對應每個長度的位置可以放攻擊塔,有三種:

  • 紅塔:怪在紅塔所單位長度內每秒受到x點傷害。
  • 綠塔:怪經過綠塔之後,每秒受到y點傷害。
  • 藍塔:怪經過後每走一格的時間加上z。
    求最大傷害。

解題思路:更具塔的性質,紅塔肯定放在最後,所以有dp[i][j]表示到第i個位置,放j個藍塔造成的傷害值最大為多少。並且過程中維護ans最大(要加上後面紅塔的攻擊傷害),對於一個狀態dp[i][j],除了轉移到dp[i+1][j]和dp[i+1][j+1]之外,可以將後面n-i個位置視為放紅塔,去維護ans。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef unsigned long long ll;const int maxn = 1505;int N;ll x, y, z, T;ll dp[maxn][maxn];ll solve () {    ll ans = 0;    memset(dp, 0, sizeof(dp));    for (int i = 0; i < N; i++) {        for (int j = 0; j <= i; j++) {            ll v = (T + j * z);            ll w = v * (i-j) * y;            dp[i+1][j] = max(dp[i+1][j], dp[i][j] + w);            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + w);            ans = max(ans, dp[i][j] + (x * v + w) * (N-i));        }    }    for (int i = 0; i <= N; i++)        ans = max(ans, dp[N][i]);    return ans;}int main () {    int cas;    scanf("%d", &cas);    for (int kcas = 1; kcas <= cas; kcas++) {        scanf("%d%I64u%I64u%I64u%I64u", &N, &x, &y, &z, &T);    //    scanf("%d%lld%lld%lld%lld", &N, &x, &y, &z, &T);    //    printf("Case #%d: %lld\n", kcas, solve());        printf("Case #%d: %I64u\n", kcas, solve());    }    return 0;}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.