1134 最长递增子序列(暴力写的)

可以用二分写...

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题

 收藏

 关注

给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)

例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。

Input

第1行:1个数N,N为序列的长度(2 <= N <= 50000)
第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9)

Output

输出最长递增子序列的长度。

Input示例

8
5
1
6
8
2
4
5
10

Output示例

5

相关问题

最长递增子序列 V2

160

最长递增子序列的数量

160

break  很是巧妙...

代码:

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <string>
 5 #include <algorithm>
 6 #include <queue>
 7 #include <stack>
 8 #include <map>
 9 #include <set>
10 #include <vector>
11 #include <iostream>
12 using namespace std;
13 #define for0(i, n) for(int i=0; i<(n); ++i)
14 #define for1(i,a,n) for(int i=(a);i<=(n);++i)
15 #define for2(i,a,n) for(int i=(a);i<(n);++i)
16 #define for3(i,a,n) for(int i=(a);i>=(n);--i)
17 #define for4(i,a,n) for(int i=(a);i>(n);--i)
18 #define CC(i,a) memset(i,a,sizeof(i))
19 #define LL long long
20 #define MOD 1000000007
21 #define INF 0x3f3f3f3f
22 #define MAX 50100
23
24 int dp[MAX],num[MAX];
25 int n;
26
27 int main()
28 {
29     scanf("%d",&n);
30     memset(dp,INF,sizeof(dp));
31     memset(num,INF,sizeof(num));
32     for(int i=0; i<n; i++)
33         scanf("%d",&dp[i]);
34     int path=0;
35     for(int i=0; i<n; i++){
36         for(int j=0; j<n; j++){
37             if(dp[i]<num[j]){
38                 num[j]=dp[i];
39                 if(path<j)
40                     path=j;
41                 break;
42             }
43         }
44     }
45     printf("%d\n",path+1);
46 }
时间: 2024-08-28 05:12:53

1134 最长递增子序列(暴力写的)的相关文章

51nod 1134 最长递增子序列 (O(nlogn)算法)

1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10. Input 第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9) Output 输

[2016-05-11][51nod][1134 最长递增子序列]

时间:2016-05-11 14:16:50 星期三 题目编号:[2016-05-11][51nod][1134 最长递增子序列] 题目大意:给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 分析: 维护一个栈,如果是更大值,加入栈顶,否则,替换栈内第一个不小于它的数字 #include<stdio.h> #include<algorithm> #include<string.h> using namespace std; co

51node 1134 最长递增子序列 (数据结构)

题意: 最长递增子序列 思路: 普通的$O(n^2)$的会超时.. 然后在网上找到了另一种不是dp的写法,膜拜一下,自己写了一下解释 来自:https://blog.csdn.net/Adusts/article/details/80764782 代码: #include<stdio.h> #include<vector> #include<algorithm> using namespace std; int main() { int n = 0, buf = 0,

51nod 1134 最长递增子序列

给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10. Input 第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9) Output 输出最长递增子序列的长度. Input示例 8 5 1 6 8 2 4 5 10 Output示例 5 //第一种做法,放

LCS 51Nod 1134 最长递增子序列

给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10. Input 第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9) Output 输出最长递增子序列的长度. Input示例 8 5 1 6 8 2 4 5 10 Output示例 5 #include

【51NOD-0】1134 最长递增子序列

[算法]动态规划 [题解]经典模型:最长上升子序列(n log n) #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn=50010; int a[maxn],b[maxn],f[maxn],n,m; int find(int x) { int l=1,r=m+1;//m+1是永远不可能被直接比较的,但是必须有 while(l<r) {

51Nod 1134 最长递增子序列(动态规划O(nlogn))

1 #include <iostream> 2 #include <algorithm> 3 #include <stdio.h> 4 #define MAXN 50010 5 using namespace std; 6 7 const int MIN = -1e9; 8 9 int main(void){ 10 int n, a[MAXN], vis[MAXN], len = 1; 11 scanf("%d", &n); 12 for (

最大子数组之和、最大子数组之积、最长递增子序列求法

昨天做爱奇艺笔试题,最后一道编程题是求整型数组最长递增子序列,由于时间关系,没有完全写出来,今天重新来做做这一系列题. <1> 最大子数组之和 首先从最简单的最大子数组之和求取.数组里有正数.负数.零.设包含第 i 个元素的子数组的和为 Sum,则Sum的值为 Sum(i) = Sum(i-1) + arrey[i]; 显然如果arrey[i]<=0,则Sum(i)<=Sum(i-1);则必须把Sum(i)=arrey[i];同时maxSum用来保存Sum最大值.时间复杂度为o(n

求数组中最长递增子序列

编程之美有一道关于数组中最长递增子序列,题目如下: 写一个时间复杂度尽可能低的程序,求一个一维数组(N个元素)中最长递增子序列的长度. 例如在序列1,-1,2,-3,4,-5,6,-7中,其最长的递增子序列的长度为4(如1,2,4,6),从该书给的例子我们可以知道的是其最长的递增子序列可以不连续的. 作者利用动态规划方法给了三种解法. 解法一: 根据无后效性的定义,各阶段按照一定的次序排列好之后,对于某个给定阶段的状态来说,它以前各阶段的状态无法直接影响它未来的决策,而只能间接地通过当前状态来影