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

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

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

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

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

时间: 2024-07-31 14:34:47

poj 2533 poj 2533 poj 2533 记忆式搜索1 2的相关文章

poj 最长公共子序列 1458 记忆式搜索

#include <iostream>using namespace std;#include<cstring>#define N 1005char s1[N],s2[N];int dp[N][N];int max(int a,int b) {  return a>b ? a:b ;} int f(int x ,int y){ if(dp[x][y]!=-1) return dp[x][y]; if(x==0||y==0)    return dp[x][y]=0; else

POJ 2704 Pascal&#39;s Travels (基础记忆化搜索)

Pascal's Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5328   Accepted: 2396 Description An n x n game board is populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate path from t

(RQoj 15 采药------rwkj 10.1.5.253 1447) 记忆式搜索 2

#include <iostream>#include <string.h>using namespace std;int dp[105][1005], w[105],v[105],T,M,;int max(int x,int y) { return x>y?x:y; }int f(int x,int y){ int t; if (dp[x][y]!=-1) return dp[x][y]; if ( x==M+1 || y==0 ) return dp[x][y]=0; e

(RQoj 15采药------rwkj 10.1.5.253 1447) 记忆式搜索 1

#include <iostream>using namespace std;int dp[105][1005],w[105],v[105] ; int max(int a,int b) { return a > b ? a : b; }int f(int x,int y){ int t ; if(dp[x][y]!=-1) return dp[x][y] ; if(x==0 || y==0 ) return dp[x][y]=0 ; else { t=f(x-1,y) ; if(y&g

nyist 17 -----记忆式搜索------Accept

//记忆式搜索 #include <iostream>#include<stdio.h>#include<string.h>using namespace std;char a[10002];int b[10002];int n,ans;int f(int x){ int i,t; if(b[x]>0) return b[x]; b[x]=1; for(i=0;i<=x-1;i++) { t=f(i); if(a[i]<a[x] &&

ppt Fibonacii数列的第n项------记忆式搜索

#include <stdio.h>#define MAX 50+1int a[MAX];int fib(int n){ if (a[n]==-1)     return   a[n]=fib(n-1)+fib(n-2);           else          return   a[n]; }int main( ){ int i,n; for(i=1; i<MAX; i++) a[i]=-1; a[0]=a[1]=1; scanf("%d",&n);

POJ 1579 Function Run Fun 【记忆化搜索入门】

题目传送门:http://poj.org/problem?id=1579 Function Run Fun Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20560   Accepted: 10325 Description We all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c): if a <=

poj 1088 滑雪(区间dp+记忆化搜索)

题目链接:http://poj.org/problem?id=1088 思路分析: 1>状态定义:状态dp[i][j]表示在位置map[i][j]可以滑雪的最长区域长度: 2>状态转移方程:由于由位置[i, j]只能向四个方向移动,所以子问题最多有四个:所以dp[i][j]为其邻域可以滑雪的最大区域长度加上从该位置滑到邻域的长度,即1: 代码如下: #include <cstdio> #include <iostream> #include <algorithm&

(中等) POJ 1054 The Troublesome Frog,记忆化搜索。

Description In Korea, the naughtiness of the cheonggaeguri, a small frog, is legendary. This is a well-deserved reputation, because the frogs jump through your rice paddy at night, flattening rice plants. In the morning, after noting which plants hav