#include <bits/stdc++.h>
using namespace std;
const int roz=607;
int n;
string s[roz];
set<string> secik;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i=0; i<n; i++)
cin >> s[i];
for(int a=0; a<n; a++)
{
for(int b=0; b<n; b++)
{
int wyn=0;
string dryb=s[a]+s[b];
secik.clear();
for(int i=1; i<(1<<dryb.size()); i++)
{
if(__builtin_popcount(i)%2==0)
{
int bilans=0;
string slowo;
for(int j=0; j<(dryb.size()); j++)
{
if(i&(1<<j))
{
slowo+=dryb[j];
if(dryb[j]=='L')
bilans++;
else
{
bilans--;
if(bilans<0)
break;
}
}
}
if(bilans==0)
secik.insert(slowo);
}
}
cout << secik.size() << ' ';
}
cout << '\n';
}
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 | #include <bits/stdc++.h> using namespace std; const int roz=607; int n; string s[roz]; set<string> secik; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i=0; i<n; i++) cin >> s[i]; for(int a=0; a<n; a++) { for(int b=0; b<n; b++) { int wyn=0; string dryb=s[a]+s[b]; secik.clear(); for(int i=1; i<(1<<dryb.size()); i++) { if(__builtin_popcount(i)%2==0) { int bilans=0; string slowo; for(int j=0; j<(dryb.size()); j++) { if(i&(1<<j)) { slowo+=dryb[j]; if(dryb[j]=='L') bilans++; else { bilans--; if(bilans<0) break; } } } if(bilans==0) secik.insert(slowo); } } cout << secik.size() << ' '; } cout << '\n'; } return 0; } |
English