Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //Programming Magic Here. Works in O(n^4). Could be optimized with DP.
- vector<string> getH(int n) {
- int size = (int)pow(5, n);
- vector<string> ans(size, string(size, ' '));
- if (n == 1) {
- return {
- "H H",
- "H H",
- "HHHHH",
- "H H",
- "H H"
- };
- }
- vector<string> smallerH = getH(n - 1);
- int smallerSize = size / 5;
- for (int i = 0; i < 5; i++) {
- for (int j = 0; j < 5; j++) {
- if (j == 0 || j == 4 || i == 2) {
- for (int a = 0; a < smallerSize; a++) {
- for (int b = 0; b < smallerSize; b++) {
- ans[i * smallerSize + a][j * smallerSize + b] = smallerH[a][b];
- }
- }
- }
- }
- }
- return ans;
- }
- int main() {
- //Input
- int n;
- cin >> n;
- auto ans = getH(n);
- //Output
- for (auto a : ans) cout << a << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement