找着规律即可~,再就是处理字符串
//============================================================================// Name : 825.cpp// Author : // Version :// Copyright : Your copyright notice// Description : Hello World in C++, Ansi-style//============================================================================#include#include #include using namespace std;char s[1000];int a[1000][1000], b[1000][1000];int N, t, t1, m, n, len, num, tag;int main() { freopen("a.txt", "r", stdin); int T = 0; while(scanf("%d", &N)!=EOF){ getchar(); while(N--){ gets(s); scanf("%d%d", &m, &n); getchar(); for(int i = 1;i <= m;i++){ gets(s); t = 0; len = strlen(s); num = 0; while(t < len){ while(s[t] == ' '&&s[t]!='\n'){ t++; } t1 = 0; while(isdigit(s[t])){ t1 = t1*10+(s[t]-'0');// printf("") t++; }// printf("%d\n", t1); if(t1!=0){ if(num == 0){ num++; continue; } else{ a[i][num] = t1; num++; } } } a[i][0] = num-1; }// for(int i = 1;i <= m;i++){// printf("%d: ", a[i][0]);// for(int j = 1;j <= a[i][0];j++){// printf(" %d", a[i][j]);// }// printf("\n");// } memset(b, -1, sizeof(b)); for(int i = 1;i <= m;i++){ for(int j = 1;j <= a[i][0];j++){ b[i][a[i][j]] = 0; } } tag = 0; for(int i = 1;i <= m;i++){ if(b[i][1] == 0){ tag = 1; } if(tag == 1){ b[i][1] = 0; } else if(tag == 0){ b[i][1] = 1; } } tag = 0; for(int i = 1;i <= n;i++){ if(b[1][i] == 0){ tag = 1; } if(tag == 1){ b[1][i] = 0; } else if(tag == 0){ b[1][i] = 1; } } for(int i = 2;i <= m;i++){ for(int j = 2;j <= n;j++){ if(b[i][j]!=0){ b[i][j] = b[i-1][j]+b[i][j-1]; } } } printf("%d\n", b[m][n]); if(N){ printf("\n"); } } } return 0;}