您的位置:首页 > Web前端

UVa 825 - Walking on the Safe Side

2013-06-22 21:13 1151 查看
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cctype>
using namespace std;
const int MAXN = 1000;
int w, n;
int d[MAXN][MAXN];
char buff[MAXN];

char * next(char *p)
{
while(isdigit(*p)) p++;
if(*p == ' ') p++;
return p;
}

void dp()
{
for(int i=1; i<=w; i++) {
for(int j=1; j<=n; j++) {
int &cur = d[i][j];
if(!cur) {
if(i==1 && j==1) cur=1;
else cur = d[i-1][j] + d[i][j-1];
} else {
cur = 0;
}
}
}
}

int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d\n", &w, &n);
memset(d, 0, sizeof(d));
int t;
char *p;
for(int i=1; i<=w; i++) {
p = buff;
gets(p);
sscanf(p, "%d", &t);
p = next(p);
while(*p) {
sscanf(p, "%d", &t);
d[i][t] = -1;
p = next(p);
}
}
dp();
printf("%d%s\n", d[w]
, T?"\n":"");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: