zoukankan      html  css  js  c++  java
  • HDU

    input:

    3 1 3 2
    4 1 2 3 4
    4 3 3 2 1
    0
    

      

    output:

    4
    10
    3
    

      

    题目大意:

    寻找严格递增的序列和。
    

      

    分析:

    LIS。dp[i]表示前i个最长递增序列和。
    

      

    code:

    #define frp
    
    #include<bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const ll INF = 0x3f3f3f3f;
    const ll inf = 0x7fffff;
    const int maxn = 1 << 15;
    const int MAXN = 10000;
    int dp[1001];
    int n, chess[1001];
    
    void solve() {
        while (cin >> n&&n) {
            for (int i = 0; i < n; i++) {
                cin >> chess[i];
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                dp[i] = chess[i];
                for (int j = 0; j < i; j++) {
                    if (chess[i] > chess[j]) {
                        dp[i] = max(dp[i], dp[j] + chess[i]);
                    }
                }
                ans=max(ans,dp[i]);
            }
            cout << ans << endl;
        }
    }
    
    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    #ifdef frp
        freopen("D:\coding\c_coding\in.txt", "r", stdin);
    //    freopen("D:\coding\c_coding\out.txt", "w", stdout);
    #endif
        solve();
        return 0;
    }
    

      

  • 相关阅读:
    psi
    firefox修改语言
    automapper
    堆喷图解
    脱壳系列_0_FSG壳_详细版
    脱壳系列_1_UPX壳_详细版
    算法01-最大子数组详解
    逆向MFC程序
    如何执行shell命令
    Unity之流光效果
  • 原文地址:https://www.cnblogs.com/visualVK/p/9692634.html
Copyright © 2011-2022 走看看