poj-1088 & nyoj-10
来源:互联网 发布:mac sublime 跳转 编辑:程序博客网 时间:2024/05/18 02:39
#include<iostream>#include<cstdio>#include<fstream>using namespace std;#define maxn 108int x[4]={1,0,-1,0};int y[4]={0,-1,0,1};int r,c,m[maxn][maxn],cnt[maxn][maxn];int MAX(int a,int b){return a>b?a:b;}int dfs(int a,int b){int i,max=1;if(cnt[a][b])return cnt[a][b];for(i=0;i<4;++i){int xx=a+x[i];int yy=b+y[i];if(m[a][b]>m[xx][yy] && xx>=1 && xx<=r && yy>=1 && yy<=c)max=MAX(max,dfs(xx,yy)+1);}cnt[a][b]=max;return cnt[a][b];}int main(){int i,j,x,y;//freopen("d:\\test.txt","r",stdin);int min=0;scanf("%d%d",&r,&c);for(i=1;i<=r;++i)for(j=1;j<=c;++j)scanf("%d",&m[i][j]);for(i=1;i<=r;++i)for(j=1;j<=c;++j)min=MAX(min,dfs(i,j));printf("%d\n",min);return 0;}
#include<iostream>#include<cstdio>#include<fstream>#include<string.h>//这个头文件特别重要using namespace std;#define maxn 108int x[4]={1,0,-1,0};int y[4]={0,-1,0,1};int r,c,m[maxn][maxn],cnt[maxn][maxn];int MAX(int a,int b){return a>b?a:b;}int dfs(int a,int b){int i,max=1;if(cnt[a][b])return cnt[a][b];for(i=0;i<4;++i){int xx=a+x[i];int yy=b+y[i];if(m[a][b]>m[xx][yy] && xx>=1 && xx<=r && yy>=1 && yy<=c)max=MAX(max,dfs(xx,yy)+1);}cnt[a][b]=max;return cnt[a][b];}int main(){int i,j,x,y;//freopen("d:\\test.txt","r",stdin);int t;scanf("%d",&t);while(t--){memset(cnt,0,sizeof(cnt));int min=0;scanf("%d%d",&r,&c);for(i=1;i<=r;++i)for(j=1;j<=c;++j)scanf("%d",&m[i][j]);for(i=1;i<=r;++i)for(j=1;j<=c;++j)min=MAX(min,dfs(i,j));printf("%d\n",min);}return 0;}
- poj-1088 & nyoj-10
- poj 1088-滑雪;NYOJ 10-skiing
- POJ 1088 滑雪 && NYOJ 10 skiing
- poj 1088/nyoj 10 滑雪(记忆化搜索/DP)
- 数据结构 动态规划DP (POJ 1088 && NYOJ 10)
- 搜索学习(1)--POJ 1088滑雪 && NYOJ 10
- poj 1088 && nyoj 10 滑雪(记忆化搜索)
- nyoj 211&&poj 3660
- POJ-1088滑雪,典型的动态规划题,与NYOJ-10skiing一样,但NYOJ上时限是3s,用搜索可以过,但在POJ上就超时了~~
- Nyoj 293 + poj 1011 Sticks
- POJ 1401&&NYOJ 954 N!
- nyoj 9 poj 2528 posters
- NYOJ 水池数目 && POJ 2386
- Nyoj 10
- POJ&&NYOJ--1328题Radar Installation
- nyoj 129 poj 1308 Is a tree
- poj 3339 nyoj 130 Snowflake Snow Snowflakes
- 0ms poj sticks || NYOJ sticks
- Android面试题(五)
- nyoj-569
- nyoj-5
- nyoj-6
- nyoj-8
- poj-1088 & nyoj-10
- windows多线程编程
- nyoj-11
- nyoj-73
- nyoj-13
- nyoj-12
- nyoj-14
- nyoj-74
- nyoj-75