#include <bits/stdc++.h> using namespace std; using PII = pair<int, int>; const int prime = 1e9 + 7; decltype(auto) left(PII &p) { return (p.first); } decltype(auto) right(PII &p) { return (p.second); } auto sum(PII &p) { return left(p) + right(p); } long long single_game2(const string& s) { vector<PII> counts(size(s) + 1); left(counts[0]) = 1; right(counts[0]) = 0; for (int i = 0; i < size(s); ++i) { char c = s[i]; if (c == 'L') { for (int j = i; j >= 0; --j) { left(counts[j + 1]) = sum(counts[j]) % prime; } } if (c == 'P') { for (int j = 1; j <= i; ++j) { right(counts[j - 1]) = sum(counts[j]) % prime; } } } return right(counts[0]); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<string> dribbles(n); for (int i = 0; i < n; ++i) { cin >> dribbles[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cout << single_game2(dribbles[i] + dribbles[j]) << " "; } 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 | #include <bits/stdc++.h> using namespace std; using PII = pair<int, int>; const int prime = 1e9 + 7; decltype(auto) left(PII &p) { return (p.first); } decltype(auto) right(PII &p) { return (p.second); } auto sum(PII &p) { return left(p) + right(p); } long long single_game2(const string& s) { vector<PII> counts(size(s) + 1); left(counts[0]) = 1; right(counts[0]) = 0; for (int i = 0; i < size(s); ++i) { char c = s[i]; if (c == 'L') { for (int j = i; j >= 0; --j) { left(counts[j + 1]) = sum(counts[j]) % prime; } } if (c == 'P') { for (int j = 1; j <= i; ++j) { right(counts[j - 1]) = sum(counts[j]) % prime; } } } return right(counts[0]); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<string> dribbles(n); for (int i = 0; i < n; ++i) { cin >> dribbles[i]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cout << single_game2(dribbles[i] + dribbles[j]) << " "; } cout << endl; } } |