HDU 4939 stupid tower defense (DP)

Source: Internet
Author: User

Link: HDU 4939 stupid tower defense

Theme: tower guard game, a road with a length of N, given X, Y, Z and T. Then, the attack tower can be placed at each length. There are three types:

  • Red Tower: X points per second damage to the red tower within the unit length.
  • Green Tower: After the monster passes through the Green Tower, it is hurt by point y every second.
  • Blue Tower: Add Z to the time each passing by a grid.
    Maximum damage.

Solution: The redtower must be placed at the end of the topic. Therefore, DP [I] [J] indicates the position I, the maximum damage caused by J blue towers. And maintain the largest ans (add the Red Tower attack damage) during the process. For a status DP [I] [J], in addition to transferring to DP [I + 1] [J] and DP [I + 1] [J + 1], you can regard the n-I positions below as the redtower, to maintain 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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.