POJ-2533 裸LIS

紫書上的模板還真是好套呢,我的代碼算是O(n3) 的複雜度吧,不不,還是個O(n3) 的算法

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define DEBUG
const int maxn=1000+5,maxv=26,INF=0x3f3f3f3f;
int n,d[maxn],a[maxn];
int dp(int i){
    int& ans=d[i];
    if(d[i]>0)return ans;
    ans=1;
    for(int j=i+1;j<=n;j++){
        if(a[j]>a[i]) ans=max(ans,dp(j)+1);
    }
    return ans;
}
int main(){
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dp(i));
    }
    printf("%d\n",ans );
#ifdef DEBUG
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}
發佈了51 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章