#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define pque priority_queue
#define vt vector
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define END(x) { cout << x; return; }
template<int D, typename T> struct vtd : public vector<vtd<D - 1, T>> {
template<typename... Args> vtd(int n = 0, Args... args) : vector<vtd<D - 1, T>>(n, vtd<D - 1, T>(args...)) {} };
template<typename T> struct vtd<1, T> : public vector<T> { vtd(int n = 0, const T& val = T()) : vector<T>(n, val) {} };
#define PI (ld)3.1415926535897932384626433832795
#define MOD (int)1000000007
#define inf (int)1000000001
#define INF (ll)1000000000000000001
#define EPS 1e-9
typedef long double ld;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#ifdef NOT_OJ
#define debug(x) cerr << #x << ": "; __print(x); cerr << "\n";
#else
#define debug(x)
#endif
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(ll t) { cerr << t; }
void __print(int t) { cerr << t; }
void __print(string t) { cerr << t; }
void __print(char t) { cerr << t; }
void __print(ld t) { cerr << t; }
void __print(double t) { cerr << t; }
void __print(ull t) { cerr << t; }
void __print(uint t) { cerr << t; }
void __print(bool t) { cerr << t; }
template <class T, class V> void __print(pair <T, V> p);
template <class T> void __print(vt <T> v);
template <class T> void __print(set <T> v);
template <class T, class V> void __print(map <T, V> v);
template <class T> void __print(multiset <T> v);
template <class T> void __print(vt <vt <T>> v);
template <int D, class T> void __print(vt <vtd <D, T>> v);
template <class T> void __print(unordered_set <T> v);
template <class T, class V> void __print(unordered_map <T, V> v);
template <class T, class V> void __print(pair <T, V> p) {cerr << "{"; __print(p.F); cerr << ","; __print(p.S); cerr << "}";}
template <class T> void __print(vt <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";}
template <class T> void __print(vt <vt <T>> v) {cerr << "\n"; for (int i = 0; i < sz(v); i++) {cerr << " "<< i << ": "; __print(v[i]); cerr << "\n";}}
template <int D, class T> void __print(vt <vtd <D, T>> v) {cerr << "\n"; for (int i = 0; i < sz(v); i++) {cerr << " "<< i << ": "; __print(v[i]); cerr << "\n";}}
template <class T> void __print(set <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";}
template <class T> void __print(unordered_set <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";}
template <class T> void __print(multiset <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void __print(map <T, V> v) {cerr << "[ "; for (auto i : v) {__print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void __print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {__print(i); cerr << " ";} cerr << "]";}
void add(int &a, int b) {
a = (a + b) % MOD;
}
vt <int> dpL, dpR, dp;
int solve(string &s) {
for (int i = 0; i < sz(dp); i++) dpL[i] = dpR[i] = dp[i] = 0;
dpL[0] = 1;
for (auto &x : s) {
if (x == 'L') {
for (int i = sz(s) - 1; i >= 0; i--) {
add(dpL[i + 1], dpL[i]);
add(dpR[i + 1], dpL[i]);
add(dp[i + 1], dpL[i]);
dpL[i] = 0;
}
}
else {
for (int i = 1; i <= sz(s); i++) {
add(dpL[i - 1], dpR[i]);
add(dpR[i - 1], dpR[i]);
add(dp[i - 1], dpR[i]);
dpR[i] = 0;
}
}
}
return dp[0];
}
void __runcase() {
int n;
cin >> n;
vt <string> v(n);
int mx = -1;
for (auto &x : v) { cin >> x; MAX(mx, sz(x)); }
dp.resize(mx * 2 + 1);
dpL.resize(mx * 2 + 1);
dpR.resize(mx * 2 + 1);
string s;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
s = v[i] + v[j];
cout << solve(s) << " ";
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int __test_cases = 1;
// cin >> __test_cases;
while(__test_cases--) {
__runcase();
}
}
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 120 121 122 123 124 125 126 127 128 129 | #include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define F first #define S second #define pb push_back #define eb emplace_back #define mkp make_pair #define pque priority_queue #define vt vector #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define END(x) { cout << x; return; } template<int D, typename T> struct vtd : public vector<vtd<D - 1, T>> { template<typename... Args> vtd(int n = 0, Args... args) : vector<vtd<D - 1, T>>(n, vtd<D - 1, T>(args...)) {} }; template<typename T> struct vtd<1, T> : public vector<T> { vtd(int n = 0, const T& val = T()) : vector<T>(n, val) {} }; #define PI (ld)3.1415926535897932384626433832795 #define MOD (int)1000000007 #define inf (int)1000000001 #define INF (ll)1000000000000000001 #define EPS 1e-9 typedef long double ld; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #ifdef NOT_OJ #define debug(x) cerr << #x << ": "; __print(x); cerr << "\n"; #else #define debug(x) #endif //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(ll t) { cerr << t; } void __print(int t) { cerr << t; } void __print(string t) { cerr << t; } void __print(char t) { cerr << t; } void __print(ld t) { cerr << t; } void __print(double t) { cerr << t; } void __print(ull t) { cerr << t; } void __print(uint t) { cerr << t; } void __print(bool t) { cerr << t; } template <class T, class V> void __print(pair <T, V> p); template <class T> void __print(vt <T> v); template <class T> void __print(set <T> v); template <class T, class V> void __print(map <T, V> v); template <class T> void __print(multiset <T> v); template <class T> void __print(vt <vt <T>> v); template <int D, class T> void __print(vt <vtd <D, T>> v); template <class T> void __print(unordered_set <T> v); template <class T, class V> void __print(unordered_map <T, V> v); template <class T, class V> void __print(pair <T, V> p) {cerr << "{"; __print(p.F); cerr << ","; __print(p.S); cerr << "}";} template <class T> void __print(vt <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";} template <class T> void __print(vt <vt <T>> v) {cerr << "\n"; for (int i = 0; i < sz(v); i++) {cerr << " "<< i << ": "; __print(v[i]); cerr << "\n";}} template <int D, class T> void __print(vt <vtd <D, T>> v) {cerr << "\n"; for (int i = 0; i < sz(v); i++) {cerr << " "<< i << ": "; __print(v[i]); cerr << "\n";}} template <class T> void __print(set <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";} template <class T> void __print(unordered_set <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";} template <class T> void __print(multiset <T> v) {cerr << "[ "; for (T i : v) {__print(i); cerr << " ";} cerr << "]";} template <class T, class V> void __print(map <T, V> v) {cerr << "[ "; for (auto i : v) {__print(i); cerr << " ";} cerr << "]";} template <class T, class V> void __print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {__print(i); cerr << " ";} cerr << "]";} void add(int &a, int b) { a = (a + b) % MOD; } vt <int> dpL, dpR, dp; int solve(string &s) { for (int i = 0; i < sz(dp); i++) dpL[i] = dpR[i] = dp[i] = 0; dpL[0] = 1; for (auto &x : s) { if (x == 'L') { for (int i = sz(s) - 1; i >= 0; i--) { add(dpL[i + 1], dpL[i]); add(dpR[i + 1], dpL[i]); add(dp[i + 1], dpL[i]); dpL[i] = 0; } } else { for (int i = 1; i <= sz(s); i++) { add(dpL[i - 1], dpR[i]); add(dpR[i - 1], dpR[i]); add(dp[i - 1], dpR[i]); dpR[i] = 0; } } } return dp[0]; } void __runcase() { int n; cin >> n; vt <string> v(n); int mx = -1; for (auto &x : v) { cin >> x; MAX(mx, sz(x)); } dp.resize(mx * 2 + 1); dpL.resize(mx * 2 + 1); dpR.resize(mx * 2 + 1); string s; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { s = v[i] + v[j]; cout << solve(s) << " "; } cout << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int __test_cases = 1; // cin >> __test_cases; while(__test_cases--) { __runcase(); } } |
English