zoukankan      html  css  js  c++  java
  • poj 2287

    贪心+dp

    # include <cstdio>
    # include <iostream>
    # include <algorithm>
    # define inf -0x7ffffff
    using namespace std;
    int a[2000],b[2000],d[1001][1001];
    int dp(int i,int j)
    {
        if (i>j) return 0;
        if (d[i][j]!=inf) return d[i][j];
        int t = j-i+1;
        if (a[j]>b[t]) return d[i][j] = dp(i,j-1)+200;
        if (a[j]<b[t]) return d[i][j] = dp(i+1,j)-200;
        if (a[j] == b[t]) return d[i][j] = max(dp(i+1,j)-200,dp(i,j-1));
    }
    int main()
    {
        int n,i,j;
        while (scanf("%d",&n)&&n)
        {
            for (i=0;i<=n;++i)
                for (j=0;j<=n;++j)
                    d[i][j] = inf;
            int ans = 0;
            for (i=1;i<=n;++i)
                scanf("%d",&a[i]);
            for (i=1;i<=n;++i)
                scanf("%d",&b[i]);
            sort(a+1,a+n+1);
            sort(b+1,b+n+1);
            printf("%d
    ",dp(1,n));
        }
        return 0;
    }
    View Code
  • 相关阅读:
    HDU-5384
    UVALive 5099
    ZOJ-2753
    HUD-5379
    HDU-5360
    HDU-5351
    HDU-5335
    HDU-5317
    HDU-2487
    常用十六进制颜色对照表代码查询
  • 原文地址:https://www.cnblogs.com/1carus/p/3415485.html
Copyright © 2011-2022 走看看