Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1031 Accepted Submission(s): 341
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<algorithm> 6 using namespace std; 7 8 9 struct node 10 { 11 int mat[22][22]; 12 }M_hxl,qqq[23]; 13 14 struct node cheng(node cur,node now,int n) 15 { 16 node ww; 17 int i,j,k; 18 memset(ww.mat,0,sizeof(ww.mat)); 19 for(i=0;i<n;i++) 20 for(k=0;k<n;k++) 21 if(cur.mat[i][k]) 22 { 23 for(j=0;j<n;j++) 24 if(now.mat[k][j]) 25 { 26 ww.mat[i][j]+=(cur.mat[i][k]*now.mat[k][j])%1000; 27 if(ww.mat[i][j]>=1000) 28 ww.mat[i][j]%=1000; 29 } 30 } 31 return ww; 32 } 33 34 void make_ini(int n,int m,int T) 35 { 36 int l,r,k; 37 while(T--) 38 { 39 scanf("%d%d%d",&l,&r,&k); 40 if(l>=n || r>=n)//题目没有给出它到范围 41 { 42 printf("0\n"); 43 continue; 44 } 45 if(k==0 && l==r)//K==0 相等的时候,1种,特判 46 { 47 printf("1\n"); 48 continue; 49 } 50 printf("%d\n",qqq[k].mat[l][r]); 51 } 52 } 53 54 int main() 55 { 56 int n,m,i,l,r,T; 57 while(scanf("%d%d",&n,&m)>0) 58 { 59 if(n==0&&m==0)break; 60 memset(M_hxl.mat,0,sizeof(M_hxl.mat)); 61 for(i=1;i<=m;i++) 62 { 63 scanf("%d%d",&l,&r); 64 M_hxl.mat[l][r]=1;//只算一次,题目给出这样到意思了么?重边算一次 65 } 66 qqq[1]=M_hxl; 67 for(i=2;i<=20;i++) 68 qqq[i]=cheng(qqq[i-1],M_hxl,n); 69 scanf("%d",&T); 70 make_ini(n,m,T); 71 } 72 return 0; 73 }
发现点击Submit可以提交.