#include<cstdio> #include<cstring> #include<cstdlib> #define MAX 102 int main(){ int t; scanf("%d",&t); while(t--){ int w,n; bool map[MAX][MAX] = {0}; char input[MAX]; scanf("%d%d\n",&w,&n); for(int i=0;i<w;i++){ fgets(input,sizeof(input),stdin); char *ptr; bool flag = true; ptr = strtok(input," "); int y; while(ptr!=NULL){ if(flag) {y = atoi(input);flag = false;} else map[y][atoi(ptr)] = true; ptr = strtok(NULL," "); } } //DP algorithm long long int dp[MAX][MAX] = {0}; for(int i=0;i<=w;i++) for(int j=0;j<=n;j++) dp[i][j] = 0; dp[0][1] = 1; for(int i=1;i<=w;i++){ for(int j=1;j<=n;j++) dp[i][j] = map[i][j] ? 0 : dp[i-1][j]+dp[i][j-1]; } printf("%lld\n",dp[w][n]); } }
把 char input[MAX]; 改成 char input[100000]; 就過囉!!!