/// CRISTA RONALDO SUWIIIIIIIIIIIIIIIIIIII #include <bits/stdc++.h> using namespace std; constexpr int maxN = 6e2+7, Mod = 1e9+7; int n; string ronaldo[maxN]; int solve(string s){ int res = 0, N = s.size(); set<string>S; for(int i=1;i<(1<<N);i++){ string essa=""; for(int j=0;j<N;j++) if((1 << j) & i) essa.push_back(s[j]); if(S.count(essa)) continue; S.insert(essa); bool ok = true; int cnt = 0; for(int x:essa){ if(x == 'L') cnt++; else cnt--; if(cnt < 0){ ok = false; break; } } if(cnt) ok = false; res += ok; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>ronaldo[i]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) cout<<solve(ronaldo[i] + ronaldo[j])<<' '; cout<<"\n"; } } /* 4 LLPLPP PPLP LLP P */
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 | /// CRISTA RONALDO SUWIIIIIIIIIIIIIIIIIIII #include <bits/stdc++.h> using namespace std; constexpr int maxN = 6e2+7, Mod = 1e9+7; int n; string ronaldo[maxN]; int solve(string s){ int res = 0, N = s.size(); set<string>S; for(int i=1;i<(1<<N);i++){ string essa=""; for(int j=0;j<N;j++) if((1 << j) & i) essa.push_back(s[j]); if(S.count(essa)) continue; S.insert(essa); bool ok = true; int cnt = 0; for(int x:essa){ if(x == 'L') cnt++; else cnt--; if(cnt < 0){ ok = false; break; } } if(cnt) ok = false; res += ok; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>ronaldo[i]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) cout<<solve(ronaldo[i] + ronaldo[j])<<' '; cout<<"\n"; } } /* 4 LLPLPP PPLP LLP P */ |