#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector <string> v(n); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { string a = v[i] + v[j]; set <string> s; for (ll mask = 1; mask < (1LL << (int)a.size()); mask++) { int sum = 0; bool ok = 1; string xd = ""; for (int k = 0; k < (int)a.size(); k++) { if ((mask >> k) & 1) { if (a[k] == 'L') sum++; else sum--; xd += a[k]; if (sum < 0) ok = 0; } } if (ok && sum == 0) { s.insert(xd); } } cout << (int)s.size() << " "; } cout << "\n"; } }
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 | #include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector <string> v(n); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { string a = v[i] + v[j]; set <string> s; for (ll mask = 1; mask < (1LL << (int)a.size()); mask++) { int sum = 0; bool ok = 1; string xd = ""; for (int k = 0; k < (int)a.size(); k++) { if ((mask >> k) & 1) { if (a[k] == 'L') sum++; else sum--; xd += a[k]; if (sum < 0) ok = 0; } } if (ok && sum == 0) { s.insert(xd); } } cout << (int)s.size() << " "; } cout << "\n"; } } |