Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

DP结果要比贪心靠谱多了

Posted by wchrt at 2014-04-20 22:56:32 on Problem 2287
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int cmp(int x,int y)
{
    return x<y;
}
int a[10010];
int b[10010];
int n;
int dp[1010][1010];
void gan()
{
    int k=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=-i;
        if(a[i]>=b[k+1])
        {
            k++;
        }
        for(int j=1;j<=k;j++)
        {
            if(a[i]>b[j])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else if(a[i]<b[j])
            {
                dp[i][j]=dp[i-1][j]-1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j]-1,dp[i-1][j-1]);
            }
        }

    }
    int m=dp[n][0];
    for(int i=1;i<=k;i++)
    {
        m=max(m,dp[n][i]);
    }
    printf("%d\n",m*200);
}
int main()
{
    while(~scanf("%d",&n)&&n!=0)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&b[i]);
        }
        sort(a+1,a+1+n,cmp);
        sort(b+1,b+1+n,cmp);
        memset(dp,0,sizeof(dp));
        gan();
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator