The input is wa many times, mainly because there may be more than one space between the two numbers. All of them are calculated by one space before.
#include<cstdlib>#include<iostream>#include<cstdio>#include<cmath>#include<set>#include<cstring>#include <algorithm>#define inf 0x7fffffff#define N 105#define MIN 1e-11#define M 10000#define LL long longusing namespace std;int n,k,h,t,m;int ma[N][N];char str[10000];int main(){#ifndef ONLINE_JUDGE freopen("ex.in","r",stdin);#endif scanf("%d%*c%*c",&t); while(t--) { memset(ma,0,sizeof(ma)); scanf("%d%d%*c",&n,&m); int temp; for(int i=1; i<=n; i++) { scanf("%d",&temp); gets(str); temp=0; for(int j=0;str[j];j++) { if(isdigit(str[j])) temp=temp*10+str[j]-'0'; else { if(temp) { ma[i][temp]=-1; } temp=0; } } if(temp) ma[i][temp]=-1; } ma[1][1]=1; for(int i=1; i<=n; ++i) { for(int j=1; j<=m; ++j) { if(ma[i][j]==-1) { ma[i][j]=0; continue; } if(i==1&&j==1) continue; ma[i][j]=ma[i-1][j]+ma[i][j-1]; } } printf("%d\n",ma[n][m]); if(t) printf("\n"); } return 0;}