#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=607;
string s[N];
ll V[N][N][2];
ll DP[N][N][2];
int DP1[N][2];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
clock_t czas=clock();
int n;
cin>>n;
//n=600;
for(int i=1;i<=n;i++)
{
cin>>s[i];
/* for(int l=0;l<600;l++)
{
if(l%2==0) s[i]+='L';
else s[i]+='R';
}*/
s[i]='#'+s[i];
}
for(int i=1;i<=n;i++)
{
int m=sz(s[i])-1;
memset(DP,0,sizeof DP);
int c=0;
DP[m][0][1]=1;
for(int j=m;j>=0;j--)
{
if(s[i][j]=='L') DP[j-1][0][0]+=DP[j][0][0];
else c++;
for(int l=0;l<=c;l++)
{
while(DP[j][l][0]>=mod) DP[j][l][0]-=mod;
while(DP[j][l][1]>=mod) DP[j][l][1]-=mod;
if(j==0) continue;
if(s[i][j]=='L')
{
if(l>0)
{
DP[j-1][l-1][0]+=DP[j][l][0];
DP[j-1][l-1][1]+=DP[j][l][0];
}
DP[j-1][l][1]+=DP[j][l][1];
}
else
{
DP[j-1][l+1][0]+=DP[j][l][1];
DP[j-1][l+1][1]+=DP[j][l][1];
DP[j-1][l][0]+=DP[j][l][0];
}
}
}
for(int l=0;l<=m;l++) for(int j=0;j<2;j++) V[i][l][j]=DP[0][l][j];
}
for(int i=1;i<=n;i++)
{
int m=sz(s[i])-1;
memset(DP1,0,sizeof DP1);
DP1[0][0]=1;
int c=0;
for(int j=1;j<=m;j++)
{
if(s[i][j]=='L')
{
c++;
for(int j=c;j>0;j--)
{
DP1[j][0]=DP1[j-1][0]+DP1[j-1][1];
if(DP1[j][0]>=mod) DP1[j][0]-=mod;
}
}
else
{
for(int j=0;j<=c;j++)
{
DP1[j][1]=DP1[j+1][0]+DP1[j+1][1];
if(DP1[j][1]>=mod) DP1[j][1]-=mod;
}
}
}
for(int j=1;j<=n;j++)
{
ll ans=0;
for(int l=0;l<=m;l++)
{
ans=(ans+(ll)DP1[l][0]*V[j][l][0]+(ll)DP1[l][1]*V[j][l][1])%mod;
}
cout<<ans<<" ";
}
cout<<endl;
}
/*czas=clock()-czas;
cout << "Czas " << (float)czas/CLOCKS_PER_SEC << " seconds" << endl;*/
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 113 114 115 116 117 118 119 | #include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; const int N=607; string s[N]; ll V[N][N][2]; ll DP[N][N][2]; int DP1[N][2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); clock_t czas=clock(); int n; cin>>n; //n=600; for(int i=1;i<=n;i++) { cin>>s[i]; /* for(int l=0;l<600;l++) { if(l%2==0) s[i]+='L'; else s[i]+='R'; }*/ s[i]='#'+s[i]; } for(int i=1;i<=n;i++) { int m=sz(s[i])-1; memset(DP,0,sizeof DP); int c=0; DP[m][0][1]=1; for(int j=m;j>=0;j--) { if(s[i][j]=='L') DP[j-1][0][0]+=DP[j][0][0]; else c++; for(int l=0;l<=c;l++) { while(DP[j][l][0]>=mod) DP[j][l][0]-=mod; while(DP[j][l][1]>=mod) DP[j][l][1]-=mod; if(j==0) continue; if(s[i][j]=='L') { if(l>0) { DP[j-1][l-1][0]+=DP[j][l][0]; DP[j-1][l-1][1]+=DP[j][l][0]; } DP[j-1][l][1]+=DP[j][l][1]; } else { DP[j-1][l+1][0]+=DP[j][l][1]; DP[j-1][l+1][1]+=DP[j][l][1]; DP[j-1][l][0]+=DP[j][l][0]; } } } for(int l=0;l<=m;l++) for(int j=0;j<2;j++) V[i][l][j]=DP[0][l][j]; } for(int i=1;i<=n;i++) { int m=sz(s[i])-1; memset(DP1,0,sizeof DP1); DP1[0][0]=1; int c=0; for(int j=1;j<=m;j++) { if(s[i][j]=='L') { c++; for(int j=c;j>0;j--) { DP1[j][0]=DP1[j-1][0]+DP1[j-1][1]; if(DP1[j][0]>=mod) DP1[j][0]-=mod; } } else { for(int j=0;j<=c;j++) { DP1[j][1]=DP1[j+1][0]+DP1[j+1][1]; if(DP1[j][1]>=mod) DP1[j][1]-=mod; } } } for(int j=1;j<=n;j++) { ll ans=0; for(int l=0;l<=m;l++) { ans=(ans+(ll)DP1[l][0]*V[j][l][0]+(ll)DP1[l][1]*V[j][l][1])%mod; } cout<<ans<<" "; } cout<<endl; } /*czas=clock()-czas; cout << "Czas " << (float)czas/CLOCKS_PER_SEC << " seconds" << endl;*/ return 0; } |
English