2016年8月26日星期五

longest increasing subsequence VS strictly longest increasing subsequence

longest increasing subsequence


int n;
vector vec;
const int MAXN = 100010;
const int INF = 0x3f3f3f3f;
int dp[MAXN];
int main() {
    cin >> n;
    for (int i = 0;i < n;i ++) {
        int tmp;
        scanf("%d",&tmp);
        vec.push_back(tmp);
    }
    fill(dp,dp + n,INF);
    int len = vec.size();
    for (int i = 0; i < len;i ++) {
        *upper_bound(dp,dp + n,vec[i]) = vec[i];
    }
    int ans = lower_bound(dp,dp + n,INF) - dp;
    cout << ans << endl;
}


strictly longest increasing subsequence


int n;
vector vec;
const int MAXN = 100010;
const int INF = 0x3f3f3f3f;
int dp[MAXN];
int main() {
    cin >> n;
    for (int i = 0;i < n;i ++) {
        int tmp;
        scanf("%d",&tmp);
        vec.push_back(tmp);
    }
    fill(dp,dp + n,INF);
    int len = vec.size();
    for (int i = 0; i < len;i ++) {
        *lower_bound(dp,dp + n,vec[i]) = vec[i];
    }
    int ans = lower_bound(dp,dp + n,INF) - dp;
    cout << ans << endl;
}

没有评论:

发表评论