티스토리 뷰
14495번: 피보나치 비스무리한 수열
피보나치 비스무리한 수열은 f(n) = f(n-1) + f(n-3)인 수열이다. f(1) = f(2) = f(3) = 1이며 피보나치 비스무리한 수열을 나열하면 다음과 같다. 1, 1, 1, 2, 3, 4, 6, 9, 13, 19, ... 자연수 n을 입력받아 n번째 피보
www.acmicpc.net
백준 소스코드 [C++] 14495 피보나치 비스무리한 수열
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <deque>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <sstream>
#include <cstdlib>
#include <cassert>
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define pli pair<ll, int>
#define make_unique(v) sort(all(v)), v.erase(unique(all(v)), v.end())
typedef long long ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
ll first = 1, second = 1, third=1, fourth=1;
for (int i = 3;i < n;i++) {
fourth = first+third;
first = second;
second = third;
third = fourth;
}
cout << third << '\n';
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 11401 이항 계수 3 (0) | 2020.11.08 |
---|---|
백준 소스코드 [C++] 1074 Z (0) | 2020.11.01 |
백준 소스코드 [C++] 15624 피보나치 수 7 (0) | 2020.10.30 |
백준 소스코드 [C++] 1788 피보나치 수의 확장 (0) | 2020.10.30 |
백준 소스코드 [C++] 4150 피보나치 수 (0) | 2020.10.30 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 강한 순환 참조
- 코딩대회
- 포드 풀커슨 알고리즘
- Testable
- 부스트캠프 6기
- 컴퓨터 추상화
- 벨만포드 알고리즘
- CompositionalLayout
- WWDC16
- observeOn
- MeTal
- 최단경로 알고리즘
- 네트워크 플로우
- State Restoration
- test coverage
- 최대 매칭
- IOS
- 다익스트라 시간복잡도
- WWDC19
- mach-o
- HIG
- rxswift
- CPU와 Memory
- 최단경로 문제
- WWDC17
- 네트워크 유량
- 최단경로문제
- 벨만포드 시간복잡도
- WWDC21
- 에드몬드 카프 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함