Algorithm
[BOJ] 2193번 : 이친수
rudgh99_algo
2024. 9. 1. 15:02
1. problem :
https://www.acmicpc.net/problem/2193
2. solution 1 :
#include <bits/stdc++.h>
using namespace std;
int n;
long long d[95];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
d[1] = 1, d[2] = 1;
for (int i = 3; i <= n; i++) d[i] = d[i - 1] + d[i - 2];
cout << d[n] << '\n';
}
3. solution 2 :
// Authored by : Hot6Mania
// Co-authored by : -
// http://boj.kr/62b94c1ad9254f87a1f6e37323f2c5bf
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll d[100][2];
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
d[1][1] = 1LL;
for(int i = 2; i <= n; ++i){
d[i][0] = d[i-1][0] + d[i-1][1];
d[i][1] = d[i-1][0];
}
cout << d[n][0] + d[n][1];
}
source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/2193.cpp
basic-algo-lecture/0x10/solutions/2193.cpp at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com