poj 2533 错误的递归函数

#include <iostream>
#define N 10005
using namespace std;
int a[N],n;
int f( int x)
{	int i,t;
	if (x==0) return 1;                //第一个元素 下标为0
	for (t=0,i=0;i<x; i++)             //下标不为0
   		if (a[x]>=a[i]) t=max(f(i)+1,t);     //  f(i)+1此时的长度+1,,,,t 原来的长度
	return t;
}
int main(int argc, char *argv[])
{	int i,j;
	cin>>n;
	for (i=0;i<n; i++)
		 cin>>a[i];
	cout<<f(n-1)<<endl;
	return 0;
}
#include <iostream>
#define N 10005
using namespace std;
int a[N],n;
int f( int x)
{	int i,t;
	if (x==0) return 1;
	for (t=0,i=0;i<x; i++)
		if (a[x]>a[i]) t=max(f(i),t);
	return t+1;
}
int main(int argc, char *argv[])
{	int i,j;
	cin>>n;
	for (i=0;i<n; i++)
		 cin>>a[i];
	cout<<f(n-1)<<endl;
	return 0;
}

#include <iostream>
#define N 10005
using namespace std;
int a[N],n;
int f( int x)
{ int i,t;
 if (x<=0) return 1;
 t=1;
 for (i=0;i<x; i++)
  if (a[x]>a[i]) t=max(f(i)+1,t);                 //  f(i)+1此时的长度+1,,,,t 原来的长度
                                                                           // 有时候对,有时候不对
 return t;
}
int main(int argc, char *argv[])
{ int i,j;
 cin>>n;
 for (i=0;i<n; i++)
   cin>>a[i];
 cout<<f(n-1)<<endl;

return 0;
}

poj 2533 错误的递归函数

时间: 2024-10-21 02:47:34

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;