The main topic: each small representative can walk to the right or down a few steps, ask from the top left up to the right down the total number of ways to go.
DP[I][J] How many of these squares are stored.
#include <iostream> #include <cstring>using namespace std;int n;char a[40][40];int S[40][40];__int64 dp[40] [40];int x[]={1, 0};int y[]={0, 1};__int64 dfs (int X, int Y) { if (Dp[x][y] | |!s[x][y]) return dp[x][y]; int xx, yy; for (int i=0; i<2; i++) { xx=x+x[i]*s[x][y]; Yy=y+y[i]*s[x][y]; if (xx>=0 && xx<n && yy>=0 && yy<n) Dp[x][y]+=dfs (XX,YY); } return dp[x][y];} int main () { while (cin>>n && n!=-1) {for (int i=0; i<n; i++) cin>>a[i]; for (int i=0, i<n; i++) for (int j=0; j<n; j + +) s[i][j]=a[i][j]-' 0 '; memset (DP, 0, sizeof (DP)); Dp[n-1][n-1]=1; Cout<<dfs (0,0) <<endl; } return 0;}
HDU 1208 Pascal ' s Travels (memory Search)