- 재귀는 풀리다가도 안풀리고, 안풀리다가도 풀리는 것
- 이 문제는 안풀리다 풀렸다. 기모띠
- board의 길이는 가로 / 세로 : 2N임을 파악
- 이 문제를 푼 열쇠는 f(k)=3∗f(k−1)임을 알아차린 것이다.(단 각 삼각형의 위치는 조정)
- 각 줄 끝에 필요하지 않은 공백의 출력을 막기 위해 y=x−2N 그래프를 코드상에서 구현한 것도 키포인트다.
#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<char>> board(1025, vector<char>(1025, ' '));
void recursion(int x, int y, int n){
if(n == 0) {
board[x][y] = '*';
return;
}
recursion(x, y, n-1);
recursion(x+ pow(2, (n-1)), y, n-1);
recursion(x, y+ pow(2, (n-1)), n-1);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N;
recursion(0, 0, N);
int len = pow(2, N);
for(int i = 0; i < len; ++i){
for(int j = 0; j < len; ++j){
if(j > pow(2, N) - i) continue;
cout << board[i][j];
}
cout << '\n';
}
return 0;
}