BZOJ4580/Luogu3147 [Usaco2016 Open]248

amazing

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG

#ifdef ON_DEBUG

#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x)  cout << #x << " = " << x << endl
#define Pause() system("pause")

#else

#define D_e_Line ;

#endif

struct ios{
    template<typename ATP>ios& operator >> (ATP &x){
        x = 0; int f = 1; char c;
        for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
        while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
        x*= f;
        return *this;
    }
}io;
using namespace std;

const int N = 270007;

int f[61][N];

int main(){
	int n;
    io >> n;
    int ans = 0;
    R(i,1,n){
        int x;
        io >> x;
        f[x][i] = i + 1;
        ans = Max(ans, x);
    }
    
    R(i,2,58)
        R(j,1,n){
            if(!f[i][j]) 
                f[i][j] = f[i-1][f[i-1][j]];
            if(f[i][j]) 
                ans = i;
        }
        
    printf("%d",ans);
    return 0;
}

normal

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG

#ifdef ON_DEBUG

#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x)  cout << #x << " = " << x << endl
#define Pause() system("pause")

#else

#define D_e_Line ;

#endif

struct ios{
    template<typename ATP>ios& operator >> (ATP &x){
        x = 0; int f = 1; char c;
        for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
        while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
        x*= f;
        return *this;
    }
}io;
using namespace std;

const int N = 257;

int f[N][N];

int main(){
    int n;
    io >> n;
    int ans = 0;
    R(i,1,n){
        io >> f[i][i];
        ans = Max(ans, f[i][i]);
    }
    
    R(i,1,n){
        R(l,1,n-i+1){
            int r = l + i - 1;
            R(k,l,r-1){
                if(f[l][k] == f[k+1][r]){
                    f[l][r] = Max(f[l][r], f[l][k] + 1);
                    ans = Max(ans, f[l][r]);
                }
            }
        }
    }
    
    printf("%d", ans);
    
    return 0;
}

posted @ 2019-07-18 20:10  邱涵的秘密基地  阅读(140)  评论(0编辑  收藏  举报