标签:body 0ms key 输出 namespace tin field out inpu
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 97249 | Accepted: 36874 |
Description
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Input
Output
Sample Input
5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Sample Output
25
Source
#include <iostream> #include<string.h> #include<stdio.h> using namespace std; #define mod 1000000007 int n,m; int xx[10]= {0,0,-1,1}; int yy[10]= {1,-1,0,0}; int dp[200][200],q[200][200]; int dfs(int x,int y) { if(dp[x][y]) return dp[x][y]; dp[x][y]=1; for(int i=0; i<4; i++) { int x1=x+xx[i]; int y1=y+yy[i]; if(x1<0||x1>=n||y1<0||y1>=m) continue; if(q[x1][y1]>=q[x][y]) continue; dfs(x1,y1); dp[x][y]=max(dp[x1][y1]+1,dp[x][y]); } return dp[x][y]; } int main() { scanf("%d%d",&n,&m); for(int i=0; i<n; i++) for(int j=0; j<m; j++) { scanf("%d",&q[i][j]); } int sum=0; for(int i=0; i<n; i++) for(int j=0; j<m; j++) { sum=max(sum,dfs(i,j)); } printf("%d\n",sum); }
标签:body 0ms key 输出 namespace tin field out inpu
原文地址:http://www.cnblogs.com/dongsongshou/p/6914795.html