Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 2294
- IFileDialog
- DirectX11
- C++
- algorithm
- UE5
- UnrealEngine4
- 줄 세우기
- Programmers
- 1563
- Frustum
- 티스토리챌린지
- 오블완
- RVO
- GeeksForGeeks
- Unreal Engine5
- NRVO
- directx
- C
- 팰린드롬 만들기
- UnrealEngine5
- const
- winapi
- 백준
- 프로그래머스
- 언리얼엔진5
- softeer
- RootMotion
- baekjoon
- TObjectPtr
Archives
- Today
- Total
Game Develop
[Algorithm]Baekjoon 1351번 :: 무한 수열 본문
https://www.acmicpc.net/problem/1351
1351번: 무한 수열
첫째 줄에 3개의 정수 N, P, Q가 주어진다.
www.acmicpc.net
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <sstream>
#include <memory.h>
#include <deque>
#include <set>
#include <unordered_map>
#include <stack>
#include <numeric>
using namespace std;
long long n;
int p, q;
unordered_map<long long, long long> dp;
long long GetAnswer(long long num)
{
if (dp[num] != 0) return dp[num];
long long result = GetAnswer(num / p) + GetAnswer(num / q);
return dp[num] = result;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> p >> q;
dp[0] = 1;
cout << GetAnswer(n) << endl;
}
|
cs |
아주 스탠다드한 유형의 dp문제이다. n값이 최대 1조까지 들어올 수 있으니, 그부분만 유의해서 작성하면 된다.
n값이 크다보니 dp컨테이너를 배열로하면 메모리초과니까 map을 이용해보도록 하자.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm]Baekjoon 2482번 : 색상환 (0) | 2024.03.20 |
---|---|
[Algorithm]Baekjoon 18353번 :: 병사 배치하기 (0) | 2024.03.19 |
[Algorithm]Baekjoon 1092번 :: 배 (0) | 2024.03.16 |
[Algorithm]Baekjoon 2169번 :: 로봇 조종하기 (0) | 2024.03.12 |
[Algorithm]Baekjoon 4811번 :: 알약 (0) | 2024.03.11 |