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

#include <iostream>
#define N 10005
using 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;
        }
    }         
    return m;
}
int main(int argc, char *argv[])
{ int i,j;
 cin>>n;
 for (i=0;i<n; i++)
   cin>>a[i];
        f(n-1);
 cout<<maxlen<<endl;

return 0;
}

#include <iostream>
#define N 10005
using 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;
        }
    }         
    return m;
}
int main(int argc, char *argv[])
{ int i,j;
 cin>>n;
 for (i=0;i<n; i++)
   cin>>a[i];
        f(n-1);
 cout<<maxlen<<endl;

return 0;
}

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

时间: 2024-08-09 04:43:19

poj 2533 poj 2533 普通递归超时1 2的相关文章

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 &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,

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水题-1579 将递归记录会变快

短平快递归肯定卡死,这里需要了解一个情况. 1.递归是否在很多情况再做重复工作? 2.由递归生成的“大面积数据”是否是由“小范围数据”组合而来? 如果都回答“是”.就强烈推荐“记笔记方式”.如果有笔记记录,那么查笔记,否则递归. #include <stdio.h> long s[21][21][21] = {0}; int w(int a,int b,int c) { if (a <= 0 || b <= 0 || c <= 0) return s[0][0][0]=1;

半平面交 模板 poj 3335 poj 3130 poj 1474 判断半平面交是否为空集

半平面交模板 const double pi= acos(-1.0); #define arc(x) (x / 180 * pi) const double EPS = 1e-8; const int Max_N = 105; struct Point{ double x,y; Point(){} Point(double x, double y):x(x),y(y){} Point operator - (Point p){ return Point(x- p.x , y - p.y ) ;

POJ 3670 &amp;&amp; POJ 3671 (dp)

最长不下降子序列的应用嘛.两题都是一样的. POJ 3670:求给定序列按递增或递减排列时,所需改变的最小的数字的数目. POJ 3671:求给定序列按递增排列时,所需改变的最小的数字的数目. 思路就是求最长不下降子序列,然后剩下的就是需要改变的字母. 最长不下降子序列:(我之前有写过,不懂请戳)http://blog.csdn.net/darwin_/article/details/38360997 POJ 3670: #include<cstdio> #include<cstring

poj 3090 &amp;&amp; poj 2478(法雷级数,欧拉函数)

http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式很简单:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2*f[i]-1. #include <stdio.h> #include <iostream> #include <map> #include <set> #include <stack> #include <vector> #include

二分图匹配 最大匹配数+最大点覆盖 POJ 1469+POJ 3041

最大匹配数就等于最大点覆盖,因为在图里面,凡是要覆盖的点必定是连通的,而最大匹配之后,若还有点没有覆盖到,则必定有新的匹配,与最大匹配数矛盾,如果去掉一些匹配,则必定有点没有覆盖到. POJ 1469 比较简单,用的经典的二分图匹配算法. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

POJ 1496 POJ 1850 组合计数

Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is t