#include <iostream> #include <stdio.h> #define gu getchar_unlocked #define N 601 #define M 1000000007LL using namespace std; int n; long long f1[N][3*N+1],f2[N][3*N+1]; string s; void transform1L(long long a[]) { for(int i=N-1;i;i--) { a[i+N]=a[i]; a[i]+=a[i-1]-a[i-1+N]; } a[N]=a[0]; } void transform1R(long long a[]) { for(int i=0;i<N-1;i++) { a[i+N*2]=a[i]; a[i]+=a[i+1]-a[i+1+N*2]; } a[N*3]=a[N]; } void transform2L(long long a[]) { for(int i=0;i<N-1;i++) { a[i]+=a[i+1]+a[i+N]; a[i+N]=-a[i+1]; } a[N-1]+=a[N-1+N]; a[N+N]=0; } void transform2R(long long a[]) { for(int i=N-1;i;i--) { a[i]+=a[i-1]+a[i+N*2]; a[i+N*2]=-a[i-1]; } a[0]+=a[N*2]; a[N+N*2]=0; } int main() { scanf("%d",&n); for(int i=0;i<n;i++) { cin>>s; f1[i][0]=f2[i][0]=1; for(int j=0;j<s.length();j++) { if(s[j]=='L') transform1L(f1[i]); else transform1R(f1[i]); if(s[s.length()-j-1]=='L') transform2L(f2[i]); else transform2R(f2[i]); if((j&15)==0) { for(int k=0;k<=3*N;k++) { f1[i][k]%=M; if(f1[i][k]<0) f1[i][k]+=M; } for(int k=0;k<=3*N;k++) { f2[i][k]%=M; if(f2[i][k]<0) f2[i][k]+=M; } } } for(int k=0;k<=3*N;k++) { f1[i][k]%=M; if(f1[i][k]<0) f1[i][k]+=M; } for(int k=0;k<=3*N;k++) { f2[i][k]%=M; if(f2[i][k]<0) f2[i][k]+=M; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { unsigned long long r=M-1LL; for(int k=0;k<=3*N;k++) { r+=(unsigned long long)(f1[i][k]*f2[j][k]); if((k&15)==0) r%=M; } printf("%lld ",r%M); } printf("\n"); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | #include <iostream> #include <stdio.h> #define gu getchar_unlocked #define N 601 #define M 1000000007LL using namespace std; int n; long long f1[N][3*N+1],f2[N][3*N+1]; string s; void transform1L(long long a[]) { for(int i=N-1;i;i--) { a[i+N]=a[i]; a[i]+=a[i-1]-a[i-1+N]; } a[N]=a[0]; } void transform1R(long long a[]) { for(int i=0;i<N-1;i++) { a[i+N*2]=a[i]; a[i]+=a[i+1]-a[i+1+N*2]; } a[N*3]=a[N]; } void transform2L(long long a[]) { for(int i=0;i<N-1;i++) { a[i]+=a[i+1]+a[i+N]; a[i+N]=-a[i+1]; } a[N-1]+=a[N-1+N]; a[N+N]=0; } void transform2R(long long a[]) { for(int i=N-1;i;i--) { a[i]+=a[i-1]+a[i+N*2]; a[i+N*2]=-a[i-1]; } a[0]+=a[N*2]; a[N+N*2]=0; } int main() { scanf("%d",&n); for(int i=0;i<n;i++) { cin>>s; f1[i][0]=f2[i][0]=1; for(int j=0;j<s.length();j++) { if(s[j]=='L') transform1L(f1[i]); else transform1R(f1[i]); if(s[s.length()-j-1]=='L') transform2L(f2[i]); else transform2R(f2[i]); if((j&15)==0) { for(int k=0;k<=3*N;k++) { f1[i][k]%=M; if(f1[i][k]<0) f1[i][k]+=M; } for(int k=0;k<=3*N;k++) { f2[i][k]%=M; if(f2[i][k]<0) f2[i][k]+=M; } } } for(int k=0;k<=3*N;k++) { f1[i][k]%=M; if(f1[i][k]<0) f1[i][k]+=M; } for(int k=0;k<=3*N;k++) { f2[i][k]%=M; if(f2[i][k]<0) f2[i][k]+=M; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { unsigned long long r=M-1LL; for(int k=0;k<=3*N;k++) { r+=(unsigned long long)(f1[i][k]*f2[j][k]); if((k&15)==0) r%=M; } printf("%lld ",r%M); } printf("\n"); } return 0; } |