728x90
반응형
- 깃헙 링크:
GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이
알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.
github.com
#include <iostream>
#include <algorithm> // fill_n, min,max, swap
//#include <map> // 중복 x
//#include <string> // getline
//#include <cstring> // memset, strok, strstr
//#include <vector>
//#include <queue> // priority_queue<자료형, 구현체, 비교 연산자> (중복허용)
//#include <set> // 트리, 중복 x , multiset
//#include <unordered_set>
//#include <cmath>
using namespace std;
/*
[백준 1904 c++ O] 01타일
문제:
접근: 직접 갯수를 세보다 규칙을 찾음
시간복잡도:
풀이:
//1.입력
//2.dp 바텀업
//dp[i]: i개의 타일이 있을 때 이진수의 갯수
//dp[i] = dp[i-1]+dp[i-2];
//3.출력
*/
int n;
long long dp[1000005];
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
//1.입력
cin >> n;
//2.dp 바텀업
//dp[i]: i개의 타일이 있을 때 이진수의 갯수
//dp[i] = dp[i-1]+dp[i-2];
dp[1] = 1; dp[2] = 2;
for (int i = 3; i <= n; i++) {
dp[i] = (dp[i - 1] + dp[i - 2])%15746;
}
//3.출력
cout << dp[n]%15746 << '\n';
return 0;
}
반응형
'Algorithm_BOJ(백준) > 동적프로그래밍(DP)' 카테고리의 다른 글
[백준 2579 c++ VVO] 계단 오르기 (0) | 2023.02.06 |
---|---|
[백준 1932 c++ VOO] 정수 삼각형 (0) | 2023.01.19 |
[백준 11053 c++ VOOO] 가장 긴 증가하는 부분 수열 (0) | 2023.01.19 |
[백준 15486 c++ V] 퇴사 2 (0) | 2021.09.30 |
[백준 12026 c++ V] BOJ 거리 (0) | 2021.09.30 |