poj - 2533 题解

典型的LIS问题

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 using namespace std;
 5 int a[1001];
 6 int f[1001];
 7 int main()
 8 {
 9     int n;
10     scanf("%d",&n);
11     for(int i=1;i<=n;i++)
12     {
13         scanf("%d",&a[i]);
14     }
15     for(int i=1;i<=n;i++)
16     {
17         f[i]=1;
18     }
19     for(int i=1;i<=n;i++)
20     {
21         for(int j=1;j<i;j++)
22         {
23             if(a[j]<a[i])
24             {
25                 f[i]=max(f[i],f[j]+1);
26             }
27         }
28     }
29     int res=0;
30     for(int i=1;i<=n;i++)
31     {
32         res=max(res,f[i]);
33     }
34     printf("%d\n",res);
35     return 0;
36 }
时间: 2024-10-10 04:07:44

poj - 2533 题解的相关文章

[2016-04-01][poj][2533][Longest Ordered Subsequence]

时间:2016-04-01 21:35:02 星期五 题目编号:[2016-04-01][poj][2533][Longest Ordered Subsequence] #include <cstdio> #include <algorithm> using namespace std; int dp[1000 + 10],a[1000 + 10]; int main(){ int n; while(~scanf("%d",&n)){ for(int i

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

poj 3903 &amp; poj 2533 最长上升子序列(LIS)

最长上升子序列. 做这道题之前先做了2533,再看这道题,感觉两道题就一模一样,于是用2533的代码直接交, TLE了: 回头一看,数据范围.2533 N:0~1000:3903 N :1~100000. 原因终归于算法时间复杂度. 也借这道题学习了nlgn的最长上升子序列.(学习链接:http://blog.csdn.net/dangwenliang/article/details/5728363) 下面简单介绍n^2 和 nlgn 的两种算法. n^2: 主要思想:DP: 假设A1,A2..

poj 2533

#include <stdio.h> int n,ans, a[1001],b[1001]; int main() { int i,j; scanf("%d",&n); for(i=1;i<=n;i++) {  scanf("%d",&a[i]);   b[i]=1;   } for(i=1;i<=n;i++) for(j=1;j<=i;j++) if(a[i]>a[j]&&b[j]+1>b[

poj 2533 &amp; poj 1631 Longest Ordered Subsequence( LIS果题 )

题目链接: POJ 2533:http://poj.org/problem?id=2533 POJ 1631:http://poj.org/problem?id=1631 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1,

N - Longest Ordered Subsequence POJ 2533 (最长上升子序列 )

N - Longest Ordered Subsequence Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numer

POJ 2533 Longest Ordered Subsequence(LIS模版题)

Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Accepted: 21120 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ...

poj 2533 poj 2533 poj 2533 记忆式搜索1 2

#include <iostream>#include <cstring>#define N 10005using namespace std;int a[N],b[N],n,maxlen=1;int f( int x){ int i,m,t; if ( b[x]>0 ) return b[x]; m=1; for (i=0;i<x; i++) {    t=f(i);         if (a[x]>a[i])  m=max(m,f(i)+1);       

poj 2533 poj 2533 普通递归超时1 2

#include <iostream>#define N 10005using namespace std;int a[N],n,maxlen=1;int f( int x){ int i,t,m; if (x<=0) return 1; m=1; for (i=0;i<x; i++) { t=f(i);        if (a[x]>a[i])        {   m=max(m,t+1);              if (m>maxlen) maxlen=m;