NKU 1402

#include<string.h>
#include<stdio.h>

long long matrix[35][35];
char step1[1];
int step;

int main()
{
 int n;
 while(scanf("%d",&n) != EOF)
 {
  if(n==-1)
   break;

  memset(matrix,0,sizeof(matrix));
  matrix[1][1]=1;

  for(int i=1;i<=n;i++)
  {
   for(int j=1;j<=n;j++)
   {
    scanf("%s", &step1);
    step=(int)(step1[0]-'0');
    if(j+step<=n && step!=0)
     matrix[i][j+step]+=matrix[i][j];
    if(i+step<=n && step!=0)
     matrix[i+step][j]+=matrix[i][j];
   }
  }
  printf("%lld\n",matrix[n][n]);
 }
 return 0;

}

原文地址:https://www.cnblogs.com/SQL/p/895228.html