![[백준 C++] 11727 : 2×n 타일링 2](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FkNuq7%2FbtsMuv0uFfb%2FAAAAAAAAAAAAAAAAAAAAADyAZLj7kGYoqgu440T33yNBXOSh0s-T9FTS1Uo5sBQj%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3DSsT62sVT6pdvS6ZyT4cRMpjMJzU%253D)
[백준 C++] 11727 : 2×n 타일링 2CSE/코딩 문제풀이2025. 2. 24. 18:59
Table of Contents
https://www.acmicpc.net/problem/11727
이전 글과 마찬가지로 규칙을 찾았다.
N이 1일때 1, 2일때엔 3, 3일때엔 5, 4일때엔 11..
짝수일 때에는 전 수의 2배 + 1, 홀수일 때에는 전 수의 2배 - 1로 되어 이 식을 적용하였다.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> list;
int n;
cin >> n;
list.push_back(0);
list.push_back(1);
for (int i = 2; i <= n; i++)
{
if (i % 2 == 0)
list.push_back(((list[i - 1] * 2) + 1) % 10007);
else
list.push_back(((list[i - 1] * 2) - 1) % 10007);
}
cout << list[n] << endl;
return 0;
}
'CSE > 코딩 문제풀이' 카테고리의 다른 글
[백준 C++] 17626 : Four Squares (0) | 2025.03.03 |
---|---|
[백준 C++] 2630 : 색종이 만들기 (0) | 2025.02.25 |
[백준 C++] 11726 : 2×n 타일링 (0) | 2025.02.23 |
[백준 C++] 9375 : 패션왕 신해빈 (0) | 2025.02.23 |
[백준 C++] 9095 : 1, 2, 3 더하기 (0) | 2025.02.22 |
@NiffJB :: 개발하는 니프
CSE & GAME 개발 블로그
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 부탁드립니다!