Codevs 1958 Stimulation

Source: Internet
Author: User

/*It's not difficult, but it's easy to think, but if it's memorized, it's going to kneel. We might want to use 01 maintenance next to go up or down but we ignore "each height must not be higher than the starting height" may have been recorded before the memory of the height of the current use is not the same*/#include<iostream>#include<cstdio>#include<cstring>using namespacestd;intn,m,g[ the][ the],f[ the][ the][2],ans,limit;intxx[3]={0,0,1};intyy[3]={0,1,0};intDfs (intXintYintp) {    //if (f[x][y][p]!=1) return f[x][y][p];     for(intI=1; i<=2; i++)      {          intnx=x+Xx[i]; intny=y+Yy[i]; if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&g[nx][ny]<=limit&&(P==1&&g[nx][ny]>g[x][y]) | | (p==0&&g[nx][ny]<G[x][y]))) F[X][Y][P]=max (F[x][y][p],dfs (nx,ny,p^1)+1); }    returnf[x][y][p];}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++)       for(intj=1; j<=m;j++) {scanf ("%d",&G[i][j]); f[i][j][0]=f[i][j][1]=1; }     for(intI=1; i<=n;i++)       for(intj=1; j<=m;j++) {Limit=G[i][j]; Ans=max (Ans,dfs (I,j,1)); Ans=max (Ans,dfs (I,j,0)); } printf ("%d\n", ans); return 0;}

Codevs 1958 Stimulation

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.