Zoj 3623 battle ships simple DP

Source: Internet
Author: User

Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3623.

Meaning: Give N types of ships that can be built and the opposite tower life value L, each ship gives the construction time t [I] and the output per second DPS [I], the dock can only build one ship at a time (similar to the Red Police) and ask how long it will take to destroy the tower.

Thought: DP [I] represents the amount of damage that could be caused in the previous I seconds. It reversely considers the time for the construction of each ship, the construction time used in the previous I seconds is ~ I second, the state transition equation is DP [I + T [J] = max (DP [I + T [J], DP [I] + DPS [J] * I), because the construction time of the ship is ~ T [I] + 1 ~ So there will be no overlapping construction time during status transfer.

P.s. The game was no longer witty. I understood the each time in this question as a second to create a new ship.

Code:

#include <algorithm>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#include <ctype.h>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define eps 1e-8#define INF 0x7fffffff#define maxn 10005#define PI acos(-1.0)#define seed 31//131,1313typedef long long LL;typedef unsigned long long ULL;using namespace std;int t[35],dps[35];int dp[355];int main(){    int N,L;    while(~scanf("%d%d",&N,&L))    {        memset(dp,0,sizeof(dp));        for(int i=0;i<N;i++)            scanf("%d%d",&t[i],&dps[i]);        for(int i=0;i<=L+20;i++)            for(int j=0;j<N;j++)                dp[i+t[j]]=max(dp[i+t[j]],dp[i]+dps[j]*i);        for(int i=0;i<=L+20;i++)            if(dp[i]>=L)            {                printf("%d\n",i);                break;            }    }    return 0;}

Zoj 3623 battle ships simple DP

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.