在输入上WA了很多遍,主要是因为两个数之间可能隔了不止一个空格,之前全都按照一个空格来算的。
#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 long using 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; }