链接:https://www.nowcoder.com/questionTerminal/d83721575bd4418eae76c916483493de
来源:牛客网

广场上站着一支队伍,她们是来自全国各地的扭秧歌代表队,现在有她们的身高数据,请你帮忙找出身高依次递增的子序列。 例如队伍的身高数据是(1、7、3、5、9、4、8),其中依次递增的子序列有(1、7),(1、3、5、9),(1、3、4、8)等,其中最长的长度为4。

输入描述:
输入包含多组数据,每组数据第一行包含一个正整数n(1≤n≤1000)。

紧接着第二行包含n个正整数m(1≤n≤10000),代表队伍中每位队员的身高。
输出描述:
对应每一组数据,输出最长递增子序列的长度。
示例1

输入

7
1 7 3 5 9 4 8
6
1 3 5 2 4 6

输出

4
4
大佬代码:
 #include <iostream>
using namespace std;
int main(){
    int N;
    while(cin >> N){
        int  a[], dp[] = {}, m=;
    for (int i = ; i <= N; i++) cin >> a[i];
    for (int i = ; i <= N; i++)
        for (int j = ; j < i; j++)
            if (a[j] < a[i])
                dp[i] = max(dp[i], dp[j] + ), m = dp[i] > m ? dp[i] : m;
    cout << m + << endl;
    }
    return ;
}

注意:这dp题不是很难,但在掌握后必须时刻记住有些题虽然通过这题改编,不过坑很多;

比如:

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.

The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path. 
Your task is to output the maximum value according to the given chessmen list. 

InputInput contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N 
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int. 
A test case starting with 0 terminates the input and this test case is not to be processed. 
OutputFor each case, print the maximum according to rules, and one line one case. 
Sample Input

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

Sample Output

4
10
3
 #include<iostream>
#include<algorithm>
#include<climits> using namespace std; int main()
{
int t;
while (cin >> t && t != )
{
int a[] = { }, MAX = INT_MIN, ko, b[] = { };
for (int i = ; i < t; i++)
{
cin >> a[i];
}
for (int i = ; i < t; i++)
b[i] = INT_MIN;
b[] = a[];
for (int i = ; i < t; i++)
{
for (int j = ; j < i; j++)
{
if (a[j] < a[i])
b[i] = max(b[i], b[j] + a[i]);
}
b[i] = max(b[i], a[i]);
}
for (int i = ; i < t; i++)
{
if (b[i] > MAX)
MAX = b[i];
}
cout << MAX << endl;
}
return ;
}

特别注意:有些数循环时没有进入第二层的循环,不过也应该放在b数组中进行比较,选取较大的数,相当于最长序列中题中给标记数组初始化为1;

最新文章

  1. iOS从零开始学习直播之1.播放
  2. EF的增删改查
  3. CentOS更改yum源与更新系统
  4. C#中常用的与编码有关的代码
  5. Mybatis if判断的坑
  6. 1.Knockout.Js(简介)
  7. ubuntu漂亮主题
  8. iOS开发项目名称修改
  9. Nmon 性能:分析 AIX 和 Linux 性能的免费工具
  10. Python 的枚举 Enum
  11. ECharts将折线变平滑和去掉点的属性
  12. C# 8.0的三个值得关注的新特性
  13. JDBC(4)—Preparedstatement
  14. usb枚举
  15. ios成长之每日一遍(day 2)
  16. TextView等组件的LayoutParams不能随便用,不然组件不显示
  17. Asp.Net网站的的编译与发布原理
  18. 探秘C#中的yield关键字
  19. Oracle 安全性一
  20. PAT 1078 Hashing[一般][二次探查法]

热门文章

  1. centos7 五大查找常用命令
  2. 标准盒模型、IE盒模型
  3. angular vue react web前端三大主流框架的对比
  4. Spring4之AOP
  5. Day19-File操作-创建 删除,文件过滤
  6. Javascript - Jquery - 筛选
  7. 递归求i^2的和
  8. MVC 中Delete 方法报错问题解决方案
  9. Ridis
  10. Centos6.8下卸载软件(以Mysql为例)