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;
    }
    

      

  • 相关阅读:
    密文搜索
    poj 1182 食物链
    1147. Heaps (30)
    1146. Topological Order (25)
    1145. Hashing
    1142. Maximal Clique (25)
    fzu 2112 tickets
    51nod 1554 欧姆诺姆和项链
    codeforces 963B Destruction of a Tree
    hdu 3294 Girls' research
  • 原文地址:https://www.cnblogs.com/visualVK/p/9692634.html
Copyright © 2011-2022 走看看