zoukankan      html  css  js  c++  java
  • 最长上升子序列 OpenJ_Bailian

    第一种是用以前状态更新当前状态(人人为我)

    第二种是用当前状态更新以后状态(我为人人)

    都是n^2代码:

    对于人人为我的更新方法,可以用数据结构储存“人人”对其进行线性二分优化。

    const int maxn = 1010;
    int a[maxn], maxlen[maxn];
    int main() {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            maxlen[i] = 1;
        }
        for (int i = 2; i <= n; i++) 
            for (int j = 1; j < i; j++) if (a[i] > a[j])maxlen[i] = max(maxlen[i], maxlen[j] + 1);
        cout << *max_element(maxlen + 1, maxlen + n + 1);
        return 0;
     }
    int main() {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            maxlen[i] = 1;
        }
        for (int i = 1; i <= n; i++) 
            for (int j = i+1; j <= n; j++) if (a[i] < a[j])maxlen[j] = max(maxlen[j], maxlen[i] + 1);
        cout << *max_element(maxlen + 1, maxlen + n + 1);
        return 0;
     }
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    c# 集合运算
    Nuxt
    引入js,不共享变量
    sourcetree将存在的本地项目提交到远程仓库
    c#DateTime与unix时间戳互相转换
    IfcBoundingBox
    IfcBooleanResult
    IfcAnnotationFillArea
    IfcGeometricRepresentationItem
    IfcRepresentationItem
  • 原文地址:https://www.cnblogs.com/SuuT/p/8795273.html
Copyright © 2011-2022 走看看