#include <bits/stdc++.h>
using namespace std;
int n;
string tab[602];
int main()
{
ios_base::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>tab[i];
for(int e=1;e<=n;e++)
{
for(int f=1;f<=n;f++)
{
string s = tab[e]+tab[f];
int mask_max = 1<<s.size();
set <int> S;
for(int i=1;i<mask_max;i++)
{
vector<char> v;
for(int j=0;j<s.size();j++)
{
if(i&(1<<j))
{
v.push_back(s[j]);
}
}
if(v.size()%2==0)
{
int w=0;
for(auto c: v)
{
if(c=='L')w++;
else w--;
if(w<0)
{
w=-2;
}
}
if(w==0)
{
int hasz=0;
int pot=1;
for(int j=v.size()-1;j>=0;j--)
{
if(v[j]=='L')hasz+=pot;
pot*=2;
}
if(S.find(hasz)==S.end())
{
S.insert(hasz);
}
}
}
v.clear();
}
cout<<S.size()<<" ";
}
cout<<endl;
}
}
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 | #include <bits/stdc++.h> using namespace std; int n; string tab[602]; int main() { ios_base::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++)cin>>tab[i]; for(int e=1;e<=n;e++) { for(int f=1;f<=n;f++) { string s = tab[e]+tab[f]; int mask_max = 1<<s.size(); set <int> S; for(int i=1;i<mask_max;i++) { vector<char> v; for(int j=0;j<s.size();j++) { if(i&(1<<j)) { v.push_back(s[j]); } } if(v.size()%2==0) { int w=0; for(auto c: v) { if(c=='L')w++; else w--; if(w<0) { w=-2; } } if(w==0) { int hasz=0; int pot=1; for(int j=v.size()-1;j>=0;j--) { if(v[j]=='L')hasz+=pot; pot*=2; } if(S.find(hasz)==S.end()) { S.insert(hasz); } } } v.clear(); } cout<<S.size()<<" "; } cout<<endl; } } |
English