简单dp
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
#define maxn 50
char map[maxn][maxn];
long long f[maxn][maxn];
int n;
void input()
{
for (int i = 0; i < n; i++)
scanf("%s", map[i]);
}
void work()
{
memset(f, 0, sizeof(f));
f[0][0] = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
for (int k = 0; k < i; k++)
if (map[k][j] - '0' + k == i)
f[i][j] += f[k][j];
for (int k = 0; k < j; k++)
if (map[i][k] - '0' + k == j)
f[i][j] += f[i][k];
}
}
int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d", &n), n != -1)
{
input();
work();
printf("%lld\n", f[n - 1][n - 1]);
}
return 0;
}