HDU 1987-how many ways (DP)

Source: Internet
Author: User

Resolution: Assuming that the robot is in power at this point (x, y), then it can reach the lower right corner of Manhattan, where it is less than or equal to power, and then continue searching with that point as its starting point.

The code is as follows:

#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<set>#include<map>#include<queue>#include<vector>#include<iterator>#include<utility>#include<sstream>#include<iostream>#include<cmath>#include<stack>UsingNamespace Std;Constint INF=1000000007;ConstDouble EPS=0.00000001;int row, col, Maze[101][101];int DP[101][101];Constint MoD=10000;IntDfs(int x,int y){If(x==row-1&&y==col-1)Return1; Reach the endInt& RET=dp[x][y]; Memory ofIf(ret!=-1)return ret; Ret=0;For(int STX=x; STX<=x+maze[x][y]&&stx<row; STX+ +)//find each lineFor(int sty=y; STX+sty<=x+y+maze[x][y]&&sty<col; sty+ +)//each column{If(STX!=x|| Sty!=y)//Exclude yourself{RET+=Dfs(STX, sty); Ret%=mod;}}return ret%mod;}IntMain(){int T; Cin>>t;While(T--){cin>>row>>col;For(int I=0; I<row; I++)For(Int J=0; j<col; j++)scanf("%d",&maze[i][j memset (Dp,-1 ,sizeof (Dpint ans=dfs ( Span class= "Sh-number" >0,0<<ans<<endl return 0;< Span class= "Sh-cbracket" >             

HDU 1987-how many ways (DP)

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.