#include <ios> #include <cstring> #define MOD 1000000007 #define MN 602 #define SIZ sizeof(long long)*(MN) #define ADD(A,B) {A+=B; if (A>=MOD) A-=MOD;} long long a,b,c,d,e,f,l,k,p,w,ow,n; long long dp[MN],pn[MN],ln[MN],kpwyn[MN][MN],klwyn[MN][MN]; long long wej[MN][MN],*nx,dl[MN]; __int128 ll; int main(){ scanf("%lld\n", &n); for (a=1; a<=n; ++a){ dl[a]=1; wej[a][dl[a]]=getchar_unlocked(); while (wej[a][dl[a]]=='P'||wej[a][dl[a]]=='L') wej[a][++dl[a]]=getchar_unlocked(); --dl[a]; memset(pn, 0, SIZ); memset(ln, 0, SIZ); pn[1]=1; for (b=dl[a]; b; --b){ if (wej[a][b]=='P'){ memcpy(dp, pn, SIZ); memcpy(pn+1, dp, SIZ-sizeof(long long)); pn[0]=pn[601]=0; for (c=0; c<=600; ++c){ kpwyn[a][c]+=dp[c]; ADD(ln[c], dp[c+1]); } } else{ memcpy(dp, ln, SIZ); memcpy(ln, dp+1, SIZ-sizeof(long long)); ln[600]=ln[601]=0; klwyn[a][0]+=dp[0]; for (c=1; c<=600; ++c){ klwyn[a][c]+=dp[c]; ADD(pn[c], dp[c-1]); } } } for (c=0; c<=600; ++c){ kpwyn[a][c]%=MOD; klwyn[a][c]%=MOD; } } for (a=1; a<=n; ++a){ memset(pn, 0, SIZ); memset(ln, 0, SIZ); ln[1]=1; w=0; for (b=1; b<=dl[a]; ++b){ if (wej[a][b]=='P'){ memcpy(dp, pn, SIZ); memcpy(pn, dp+1, SIZ-sizeof(long long)); pn[600]=pn[601]=0; w+=dp[0]; for (c=1; c<=600; ++c) ADD(ln[c], dp[c-1]); } else{ memcpy(dp, ln, SIZ); memcpy(ln+1, dp, SIZ-sizeof(long long)); ln[0]=ln[601]=0; w+=dp[0]; for (c=0; c<=600; ++c) ADD(pn[c], dp[c+1]); } } w%=MOD; for (b=1; b<=n; ++b){ ll=w+ln[1]*klwyn[b][0]; for (c=1; c<=600; ++c) ll+=pn[c-1]*kpwyn[b][c]+ln[c+1]*klwyn[b][c]; printf("%lld ", (long long)(ll%MOD)); } printf("\n"); } }
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 | #include <ios> #include <cstring> #define MOD 1000000007 #define MN 602 #define SIZ sizeof(long long)*(MN) #define ADD(A,B) {A+=B; if (A>=MOD) A-=MOD;} long long a,b,c,d,e,f,l,k,p,w,ow,n; long long dp[MN],pn[MN],ln[MN],kpwyn[MN][MN],klwyn[MN][MN]; long long wej[MN][MN],*nx,dl[MN]; __int128 ll; int main(){ scanf("%lld\n", &n); for (a=1; a<=n; ++a){ dl[a]=1; wej[a][dl[a]]=getchar_unlocked(); while (wej[a][dl[a]]=='P'||wej[a][dl[a]]=='L') wej[a][++dl[a]]=getchar_unlocked(); --dl[a]; memset(pn, 0, SIZ); memset(ln, 0, SIZ); pn[1]=1; for (b=dl[a]; b; --b){ if (wej[a][b]=='P'){ memcpy(dp, pn, SIZ); memcpy(pn+1, dp, SIZ-sizeof(long long)); pn[0]=pn[601]=0; for (c=0; c<=600; ++c){ kpwyn[a][c]+=dp[c]; ADD(ln[c], dp[c+1]); } } else{ memcpy(dp, ln, SIZ); memcpy(ln, dp+1, SIZ-sizeof(long long)); ln[600]=ln[601]=0; klwyn[a][0]+=dp[0]; for (c=1; c<=600; ++c){ klwyn[a][c]+=dp[c]; ADD(pn[c], dp[c-1]); } } } for (c=0; c<=600; ++c){ kpwyn[a][c]%=MOD; klwyn[a][c]%=MOD; } } for (a=1; a<=n; ++a){ memset(pn, 0, SIZ); memset(ln, 0, SIZ); ln[1]=1; w=0; for (b=1; b<=dl[a]; ++b){ if (wej[a][b]=='P'){ memcpy(dp, pn, SIZ); memcpy(pn, dp+1, SIZ-sizeof(long long)); pn[600]=pn[601]=0; w+=dp[0]; for (c=1; c<=600; ++c) ADD(ln[c], dp[c-1]); } else{ memcpy(dp, ln, SIZ); memcpy(ln+1, dp, SIZ-sizeof(long long)); ln[0]=ln[601]=0; w+=dp[0]; for (c=0; c<=600; ++c) ADD(pn[c], dp[c+1]); } } w%=MOD; for (b=1; b<=n; ++b){ ll=w+ln[1]*klwyn[b][0]; for (c=1; c<=600; ++c) ll+=pn[c-1]*kpwyn[b][c]+ln[c+1]*klwyn[b][c]; printf("%lld ", (long long)(ll%MOD)); } printf("\n"); } } |