#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n;
char map[35][35];
long long paths[35][35];
bool visited[35][35];
long long DP(int x,int y)
{
if(x < 0 || x >= n || y < 0 || y >= n)
return 0;
if(visited[x][y] == true )
return paths[x][y];
if(map[x][y] == '0')
return 0;
paths[x][y] = DP(x + map[x][y]-'0',y) + DP(x,y + map[x][y]-'0');
visited[x][y] = true;
return paths[x][y];
}
int main()
{
while(cin>>n)
{
if(n == -1)
{
break;
}
memset(paths,0,sizeof(paths));
memset(visited,0,sizeof(visited));
for(int i = 0; i < n; i++)
{
cin>>map[i];
}
paths[n-1][n-1] = 1;
visited[n-1][n-1] = true;
cout<<DP(0,0)<<endl;
}
return 0;
}
hdu 1208 DP
最新推荐文章于 2017-07-24 21:14:10 发布