#include <iostream> #include <string> #include <set> constexpr int maxN = 6e2; int n; std::string s[maxN + 1]; bool check(std::string &str) { int cnt_l = 0, cnt_p = 0; for(auto u : str) { if(u == 'L') { cnt_l++; } else { cnt_p++; } if(cnt_l < cnt_p) { return false; } } return (cnt_l == cnt_p); } int solve(std::string str) { std::set<std::string> S; std::string curr; for(int i=3; i<(1<<str.length()); i++) { if(__builtin_popcount(i) % 2 == 0) { curr = ""; for(int j=0; j<str.length(); j++) { if(i & (1 << j)) { curr += str[j]; } } S.insert(curr); } } int res = 0; for(auto u : S) { res += (int)check(u); } return res; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> n; for(int i=1; i<=n; i++) { std::cin >> s[i]; } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { std::cout << solve(s[i] + s[j]) << ' '; } std::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 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 | #include <iostream> #include <string> #include <set> constexpr int maxN = 6e2; int n; std::string s[maxN + 1]; bool check(std::string &str) { int cnt_l = 0, cnt_p = 0; for(auto u : str) { if(u == 'L') { cnt_l++; } else { cnt_p++; } if(cnt_l < cnt_p) { return false; } } return (cnt_l == cnt_p); } int solve(std::string str) { std::set<std::string> S; std::string curr; for(int i=3; i<(1<<str.length()); i++) { if(__builtin_popcount(i) % 2 == 0) { curr = ""; for(int j=0; j<str.length(); j++) { if(i & (1 << j)) { curr += str[j]; } } S.insert(curr); } } int res = 0; for(auto u : S) { res += (int)check(u); } return res; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> n; for(int i=1; i<=n; i++) { std::cin >> s[i]; } for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { std::cout << solve(s[i] + s[j]) << ' '; } std::cout << "\n"; } } |