#include <bits/stdc++.h> using namespace std; constexpr int MOD = 1e9 + 7; int length; string *dribbles; vector<vector<pair<int, int>>> allLevels; void read() { cin >> length; dribbles = new string[length]; for (int i = 0; i < length; ++i) { cin >> dribbles[i]; } } void computeLevels(vector<pair<int, int>>& levels, const string &dribbling) { for (char move: dribbling) { if (move == 'L') { pair<int, int> lastLevel = levels[levels.size() - 1]; levels.emplace_back(lastLevel.first + lastLevel.second, 0); for (int j = (int) levels.size() - 2; j > 0; --j) { levels[j].first = (levels[j - 1].first + levels[j - 1].second) % MOD; } } else { for (int j = 0; j < levels.size() - 1; ++j) { levels[j].second = (levels[j + 1].first + levels[j + 1].second) % MOD; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read(); for (int i = 0; i < length; ++i) { allLevels.emplace_back(); vector<pair<int, int>> &levels = allLevels.back(); levels.emplace_back(1, 0); computeLevels(levels, dribbles[i]); } for (int i = 0; i < length; ++i) { for (int j = 0; j < length; ++j) { vector<pair<int, int>> levels = allLevels[i]; computeLevels(levels, dribbles[j]); cout << levels[0].second; if (j < length-1) { cout << " "; } } cout << endl; } 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 54 55 56 57 58 59 | #include <bits/stdc++.h> using namespace std; constexpr int MOD = 1e9 + 7; int length; string *dribbles; vector<vector<pair<int, int>>> allLevels; void read() { cin >> length; dribbles = new string[length]; for (int i = 0; i < length; ++i) { cin >> dribbles[i]; } } void computeLevels(vector<pair<int, int>>& levels, const string &dribbling) { for (char move: dribbling) { if (move == 'L') { pair<int, int> lastLevel = levels[levels.size() - 1]; levels.emplace_back(lastLevel.first + lastLevel.second, 0); for (int j = (int) levels.size() - 2; j > 0; --j) { levels[j].first = (levels[j - 1].first + levels[j - 1].second) % MOD; } } else { for (int j = 0; j < levels.size() - 1; ++j) { levels[j].second = (levels[j + 1].first + levels[j + 1].second) % MOD; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read(); for (int i = 0; i < length; ++i) { allLevels.emplace_back(); vector<pair<int, int>> &levels = allLevels.back(); levels.emplace_back(1, 0); computeLevels(levels, dribbles[i]); } for (int i = 0; i < length; ++i) { for (int j = 0; j < length; ++j) { vector<pair<int, int>> levels = allLevels[i]; computeLevels(levels, dribbles[j]); cout << levels[0].second; if (j < length-1) { cout << " "; } } cout << endl; } return 0; } |