zoukankan      html  css  js  c++  java
  • [HDOJ1087]Super Jumping! Jumping! Jumping!

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087

    就是求最长上升子序列,但是结果求的是该序列的和,转移方程: dp[i] = max(dp[i], dp[j]+a[i])

     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <cmath>
     7 #include <queue>
     8 #include <map>
     9 #include <set>
    10 #include <stack>
    11 #include <list>
    12 #include <vector>
    13 
    14 using namespace std;
    15 
    16 inline int max(int a, int b) {
    17     return a > b ? a : b;
    18 }
    19 const int maxn = 1010;
    20 int n;
    21 int a[maxn];
    22 int dp[maxn];
    23 int ans;
    24 int main() {
    25     // freopen("in", "r", stdin);
    26     while(~scanf("%d", &n) && n) {
    27         ans = 0;
    28         for(int i = 0; i < n; i++) {
    29             scanf("%d", &a[i]);
    30         }
    31         for(int i = 0; i < n; i++) {
    32             dp[i] = a[i];
    33             for(int j = 0; j < i; j++) {
    34                 if(a[j] < a[i]) {
    35                     dp[i] = max(dp[i], dp[j] + a[i]);
    36                 }
    37             }
    38             ans = max(ans, dp[i]);
    39         }
    40         printf("%d
    ", ans);
    41     }
    42 }
  • 相关阅读:
    OC练习题
    如何将字符串@“ abc123.xyz789”倒置
    整数转换成字符串倒叙放在数组中遍历
    查找名字中有王的姓
    查询单词里包含的字符串
    OC7考核
    OC考核测试题
    OC6考核
    OC5考核
    KH8
  • 原文地址:https://www.cnblogs.com/kirai/p/4781122.html
Copyright © 2011-2022 走看看