hdu 4939 Stupid Tower Defense ( dp )

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   for   ar   

題目連結

題意:給出一條長為n個單位長度的直線,每通過一個單位長度需要t秒。

有3種塔,紅塔可以在當前格子每秒造成x點傷害,綠塔可以在之後的格子每秒造成y點傷害,藍塔可以使通過單位長度的時間增加z秒。問如何安排3種塔的順序使得造成的傷害最大,輸出最大傷害值。

分析:比賽的時候實在是沒有想出來有三種不同的 塔,每種塔的作用不同,怎麼dp。看題解才知道,應該把

所有的紅塔放到最後面,因為直線的長度是一定的,而紅塔在前面不會增加後面的傷害,然後問題就是如何安排

綠塔和藍塔,我這裡d[i][j]代表前i個直線,放j個綠塔的最大值(貌似好多人喜歡寫放藍塔,不過是一樣的)。

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #define LL __int64 7 const int maxn = 1500+10; 8 using namespace std; 9 LL d[maxn][maxn];10 11 int main()12 {13     int T, ca=1;14     LL n, x, y, z, t, i, j;15     LL ans, ret;16     scanf("%d", &T);17     while(T--)18     {19         scanf("%I64d%I64d%I64d%I64d%I64d", &n, &x, &y, &z, &t);20         ret = 0;21         memset(d, 0, sizeof(d));22         ret = n*x*t; //剛開始少了全部都是紅塔的情況,錯了好多次,因為我下面寫的是n-i;23         for(i = 1; i <= n; i++)24         {25             for(j = 0; j <= i; j++)26             {27                 LL tmp = 0;28                 if(j!=i)29                 d[i][j] = d[i-1][j]+y*j*(t+z*(i-j-1)); //第i個放藍塔30                 if(j!=0)31                 tmp = d[i-1][j-1]+y*(j-1)*(t+z*(i-j)); //第i個放綠塔32 33                 d[i][j] = max(tmp, d[i][j]);34                 ans = d[i][j]+(x+y*j)*(t+z*(i-j))*(n-i); //加上後面的傷害35                 if(ans > ret)36                 ret = ans;37             }38         }39         printf("Case #%d: %I64d\n", ca++, ret);40     }41     return 0;42 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.