[Violet 1]木偶 SRM308 DIV1 1000pt

 dp好题  

 

#line 2 "Wardrobe.cpp"
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define INF 2100000000
#define PB push_back
#define MP make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)

typedef vector VI;
typedef vector VS;
typedef vector VD;
typedef long long LL;
typedef pair PII;
#define MAXN 105

class Wardrobe
{
public:
    int cost[MAXN][MAXN];
    int f[MAXN],n;
    int match(int l,int r,vector p)
    {
        int ans=0;
        if (p[r]-p[l]<=1) return 0;
        for (int k=1;k<=r-l-1;++k)
        {
            int flag=1;
            for (int i=l;i+k<=r;++i)
                if (p[i+k]-p[i]>1) flag=false;
            if (abs(p[r-k+1]-p[l+k-1])>1&&flag) ans=k;
        }
        return ans;
    }
    int countUnscrewedHoles(vector  bolts)
    {
        memset(cost,0,sizeof cost);
        memset(f,0,sizeof f);
        n=(int)bolts.size();
        sort(bolts.begin(),bolts.end());
        for (int i=0;i=0;--j) f[i]=max(f[i],f[j]+cost[j+1][i]);
            f[i]=max(f[i],cost[0][i]);
        }
        return f[n-1];
    }
    
    // BEGIN CUT HERE

    
    // END CUT HERE
    
};

// BEGIN CUT HERE
int main()
{
    int n;
    vector a;
    Wardrobe ___test;
    while (scanf("%d",&n)==1)
    {
        a.clear();
        for (int i=1;i<=n;++i)
        {
            int x;
            scanf("%d",&x);
            a.push_back(x);
        }
            cout<<___test.countUnscrewedHoles(a)<

你可能感兴趣的:(problems)