原题:HDU-1208
从左到右、从上到下遍历每个点,然后分别往右、下更新状态就OK了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
char map[40][40];
long long dp[40][40];
int n;
int main() {
while(cin>>n&&n!=-1) {
for(int i=0; i<n; i++)
cin>>map[i];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
int t=map[i][j]-'0';
if(!t)continue;
if(i+t<n)
dp[i+t][j]+=dp[i][j];
if(j+t<n)
dp[i][j+t]+=dp[i][j];
}
}
cout<<dp[n-1][n-1]<<endl;
}
return 0;
}