티스토리 뷰
15989번: 1, 2, 3 더하기 4
정수 4를 1, 2, 3의 합으로 나타내는 방법은 총 4가지가 있다. 합을 나타낼 때는 수를 1개 이상 사용해야 한다. 합을 이루고 있는 수의 순서만 다른 것은 같은 것으로 친다. 1+1+1+1 2+1+1 (1+1+2, 1+2+1) 2+2
www.acmicpc.net
백준 소스코드 [C++] 15989 1, 2, 3 더하기 4
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
typedef long long ll;
using namespace std;
int arr[10001];
void solve(int n) {
for (int i = 4;i <= n;i++) {
int carry = (i + 4) / 6;
if (i % 6 == 0) carry++;
arr[i] = arr[i - 1] + carry;
}
cout << arr[n] << '\n';
return;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int t, n;
cin >> t;
arr[1] = 1;
arr[2] = 2;
arr[3] = 3;
while (t--) {
cin >> n;
solve(n);
}
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 15663 N과 M 9 (0) | 2020.10.29 |
---|---|
백준 소스코드 [C++] 9465 스티커 (0) | 2020.10.29 |
백준 소스코드 [C++] 15993 1, 2, 3 더하기 8 (0) | 2020.10.28 |
백준 소스코드 [C++] 11598 1, 2, 3 더하기 3 (0) | 2020.10.28 |
백준 소스코드 [C++] 12101 1, 2, 3 더하기 2 (0) | 2020.10.28 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 네트워크 플로우
- 벨만포드 알고리즘
- 부스트캠프 6기
- WWDC17
- IOS
- 다익스트라 시간복잡도
- 네트워크 유량
- 컴퓨터 추상화
- rxswift
- 코딩대회
- 벨만포드 시간복잡도
- CPU와 Memory
- 최단경로 알고리즘
- CompositionalLayout
- MeTal
- HIG
- Testable
- mach-o
- WWDC19
- observeOn
- test coverage
- 최단경로 문제
- 에드몬드 카프 알고리즘
- 포드 풀커슨 알고리즘
- WWDC21
- 최단경로문제
- WWDC16
- State Restoration
- 최대 매칭
- 강한 순환 참조
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함