#include <map>
#include <set>
#include <list>
#include <cmath>
#include<cctype>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b)
{
return a % b == 0 ? b : gcd(b, a % b);
}
#define MAXN 105
int G[MAXN][MAXN],dp[MAXN][MAXN];
int W,N;
int dx[]={0,1};
int dy[]={1,0};
bool judge(int x,int y){return (x>=1 && x<=W && y>=1 && y<=N); }
void read()
{
memset(G,0,sizeof(G));
scanf("%d%d",&W,&N);getchar();
char tmp[120];
for (int i=1;i<=W;i++)
{
gets(tmp);
// printf("%s\n",tmp);
int j=0;
while (isdigit(tmp[j])) j++;
for (int k=j+1;k<(int)strlen(tmp);k++)
{
int x=0;
while (isdigit(tmp[k]))
{
x=x*10+tmp[k]-'0';
k++;
}
G[i][x]=1;
}
}
/*for (int i=1;i<=W;i++)
{
for (int j=1;j<=N;j++)
printf("%d",G[i][j]);
putchar('\n');
}*/
}
int calcu(int x,int y)
{
if (dp[x][y]!=-1) return dp[x][y];
if (x==W && y==N) return 1;
dp[x][y]=0;
for (int i=0;i<2;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if (!G[nx][ny] && judge(nx,ny))
dp[x][y]+=calcu(nx,ny);
}
return dp[x][y];
}
int main()
{
//freopen("smaple.txt","r",stdin);
int T;
scanf("%d",&T);
while (T)
{
read();
memset(dp,-1,sizeof(dp));
printf("%d\n",calcu(1,1));
if (--T) putchar('\n');
}
return 0;
}
UVA 825 Walking on the Safe Side 读入输出+DP
最新推荐文章于 2020-02-20 20:03:08 发布