HDU 4939 Stupid Tower Defense (Greedy + dp)

Source: Internet
Author: User

HDU 4939 Stupid Tower Defense (Greedy + dp)
HDU Stupid Tower Defense

Question Link

There are some towers where the Red Tower can attack him. After the Green Tower can attack him, the blue tower can slow down and put the tower on 1-N to maximize the damage.

Thought: At first, we thought we were greedy. The Green Tower was at the beginning, and the blue tower was in the middle, and the red tower was at the end. The result was actually wrong.

However, the Red Tower is definitely at the end. This clearly does not prove much. It is a greedy idea.
Then, put dp [I] [j] to I, and there is j Green Tower in front of it to go to the status transfer.

Code:

#include 
 
  #include 
  
   #include using namespace std;const int N = 1505;typedef long long ll;int T;ll n, x, y, z, t;ll dp[N][N];ll solve() {    ll ans = n * x * t;    dp[0][0] = 0;    for (ll i = 1; i <= n; i++) {for (ll j = 0; j <= i; j++) {    dp[i][j] = 0;    if (j != i)dp[i][j] = max(dp[i][j], dp[i - 1][j] + y * j * (t + (i - j - 1) * z));    if (j)dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + y * (j - 1) * (t + (i - j) * z));    ans = max(ans, dp[i][j] + (t + (i - j) * z) * (n - i) * (x + y * j));}    }    return ans;}int main() {    int cas = 0;    scanf("%d", &T);    while (T--) {scanf("%I64d%I64d%I64d%I64d%I64d", &n, &x, &y, &z, &t);printf("Case #%d: %I64d\n", ++cas, 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.