Uvalive 4725 airport [DP]

Source: Internet
Author: User

Question connection

The DP status of this question is DP [I] [J], which indicates that the first apron of the previous I time has the maximum value when J planes fly out. Because there are only two la s, the first one is only OK, and the second one is OK.

Of course, there is still a situation where the plane is not flying enough in this question. This can be handled in advance (0, 0 and all the planes in front are flying)

Think about the trouble, but it is not unsolvable.

#include <iostream>#include <stdio.h>#include <string.h>using namespace std;#define N 5010int n;struct note{    int a,b;}dat[N];int sum[2][N];int dp[N][N];int min(int a,int b){    if(a == -1) return b;    if(a < b) return a;return b;}int main(){    int t;    cin >> t;    while(t--)    {        cin >> n;        for(int i = 1;i <= n;i++) scanf("%d%d",&dat[i].a,&dat[i].b);        for(int i = 0;i <= n;i++) for(int j = 0;j <= n;j++) dp[i][j] = -1;        dp[0][0] = 0;        sum[0][0] = sum[1][0] = 0;        for(int i = 1;i <= n;i++)        {            sum[0][i] = sum[0][i-1] + dat[i].a;            sum[1][i] = sum[1][i-1] + dat[i].b;        }        int kk = 0;        for(int i = 1;i <= n;i++)        {            if(dat[i].a == 0 && dat[i].b == 0 && sum[0][i] + sum[1][i] <= kk)            {                continue;            } else            {                kk++;                dat[kk].a = dat[i].a;                dat[kk].b = dat[i].b;            }        }        n = kk;        for(int i = 1;i <= n;i++)        {            sum[0][i] = sum[0][i-1] + dat[i].a;            sum[1][i] = sum[1][i-1] + dat[i].b;        }        //cout << n << " ";        for(int i = 0;i < n;i++)        {            for(int j = 0;j <= i;j++)            {                if(dp[i][j] == -1) continue;                if(sum[0][i+1] >= j+1)                   dp[i+1][j+1] = min(     dp[i+1][j+1],                         max(dp[i][j],max(sum[0][i+1] - j,sum[1][i+1] - (i - j))));                if(sum[1][i+1] >= i-j+1)                   dp[i+1][j] = min(    dp[i+1][j],                         max(dp[i][j],max( sum[0][i+1] - j,sum[1][i+1] - (i - j) )));            }        }        int mi = 99999999;        for(int i = 0;i <= n;i++) if(dp[n][i] != -1) mi = min(mi,dp[n][i]);        if(mi < 1) mi = 1;        printf("%d\n",mi-1);    }    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.