TYVJ 1004 Ski Memory Search

Source: Internet
Author: User

Ski

Time limit:1 Sec Memory limit:256 MB

Topic Connection http://www.tyvj.cn/p/1004
Description TRS enjoys skiing. He came to a ski resort where the ski was a rectangle, and for the sake of simplicity, we used the matrix of the R row C column to represent each piece of terrain. To get a faster speed, the glide route must be tilted downward.
For example, the rectangle in the sample, you can slide from one point to the top or bottom four adjacent points. For example 24-17-16-1, in fact 25-24-23 ... 3-2-1 longer, in fact this is the longest one.

Input

Input file

Line 1th: Two digits r,c (1<=r,c<=100), representing the rows and columns of a matrix.
2nd.. R+1 Line: The number of c per line, indicating the matrix.

Output

Output file

Only one row: outputs 1 integers representing the maximum length that can be slid.

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 Output25
HINT

Test instructions

Exercises

Ah, memory search, BFS and Dfs casual, pay attention to all the points in the queue ~\ (≧▽≦)/~ la La

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 2001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/*inline ll read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;}  int buf[10];inline void Write (int i) {int p = 0;if (i = = 0) p++;  else while (i) {buf[p++] = i% 10;i/= 10;}  for (int j = p-1; J >=0; j--) Putchar (' 0 ' + buf[j]); printf ("\ n");}*///**************************************************************************************inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intG[MAXN][MAXN];intDP[MAXN][MAXN];intdx[4]={1,-1,0,0};intdy[4]={0,0,1,-1};intMain () {intmx=0; intmy=0; intMa=0; intN=read (), m=read (); Queue<int>QX; Queue<int>qy;  for(intI=1; i<=n;i++)    {         for(intj=1; j<=m;j++) {G[i][j]=read (); DP[I][J]=1;            Qx.push (i);        Qy.push (j); }    }     while(!Qx.empty ()) {        intnowx=Qx.front (); intnowy=Qy.front ();        Qx.pop ();        Qy.pop ();  for(intI=0;i<4; i++)        {            intnextx=nowx+Dx[i]; intnexty=nowy+Dy[i]; if(nextx<1|| nextx>n| | nexty<1|| Nexty>m)Continue; if(g[nextx][nexty]<G[nowx][nowy]) {                if(dp[nowx][nowy]>=Dp[nextx][nexty]) {Dp[nextx][nexty]=dp[nowx][nowy]+1;                    Qx.push (NEXTX);                Qy.push (nexty); }            }        }    }    intans=0;  for(intI=1; i<=n;i++)    {         for(intj=1; j<=m;j++) {ans=Max (Dp[i][j],ans); }} cout<<ans<<Endl;}

TYVJ 1004 Ski Memory Search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.