이거 너비탐색은
#include <iostream>
#include <queue>
using namespace std;
class structOfData{
public:
structOfData(int _depth) : depth(_depth){}
int depth;
};
int main(){
int depthCount = 0;
int totalValue = 0;
cin >> depthCount;
queue<structOfData> q;
q.push(structOfData(1));
while (!q.empty()){
int depth>
q.pop();
if (depthData < depthCount){
depthData++;
q.push(structOfData(depthData));
q.push(structOfData(depthData));
}
else{
totalValue++;
}
}
cout << totalValue << endl;
return 0;
}
재귀는
#include <iostream>
using namespace std;
void refunc(int _maxCount,int _nowCount, int& _totalValue){
if (_maxCount == _nowCount){
_totalValue++;
return;
}
else{
_nowCount++;
refunc(_maxCount, _nowCount, _totalValue);
refunc(_maxCount, _nowCount, _totalValue);
}
}
int main(){
int depthCount = 0;
int totalValue = 0;
cin >> depthCount;
refunc(depthCount,1, totalValue);
cout << totalValue << endl;
}
맞나? 이거 ㅇㅇ 말대로 단순히 방정식화 해서 나오긴 하는데 문제 유도가 컴퓨터한테 탐색하게 해서 결과값을 도출하는거 아니냐 방성식으로하면 한줄이면 되긴 할듯
파스칼의 삼각형이지 뭐. O(1)로 끝날 문제를 비효율적인 알고리즘으로 푼다는 건 걍 무식.
ㅅㅅㅅ 맞는말이긴 한데 난 이런것도 나쁘지 않다고 생각하는데. 어차피 알고리즘이라는거 자체가 사람이 금방 추론 하는 문제를 컴퓨터는 안되니까 가이드라인을 만들어주는 과정 이라고 생각함 o(1) 로 끝나는건 결국 사람이 추론 해낸거고 그걸 방법화 시키는걸 연습하는것도 중요하지 않을까?
아 실수. O(1)이 아니라 O(N)임. 저건 O(N^2)
뭐 시간복잡도야 어찌됬건 난그렇게 생각해 ㅋㅋㅋㅋ
사실 O(lg N)에 풀 수도 있긴 하지