8000 Merge pull request #425 from neppiness/1351 · dostiny/basic-algo-lecture@16e959a · GitHub
[go: up one dir, main page]

Skip to content

Commit 16e959a

Browse files
Merge pull request encrypted-def#425 from neppiness/1351
update: 0x15 1351.cpp
2 parents 1011ad9 + 7471b96 commit 16e959a

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

0x15/solutions/1351.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : scsc3204
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/e81859b0268548ffad93a45b285dab49
44
#include <bits/stdc++.h>
55
using namespace std;
6+
typedef long long ll;
7+
8+
ll n;
9+
int p, q;
10+
unordered_map<ll, ll> um;
11+
12+
ll solve(ll x) {
13+
if(x == 0) return 1;
14+
if(um[x]) return um[x];
15+
16+
um[x] = solve(x/p) + solve(x/q);
17+
return um[x];
18+
}
619

720
int main(void){
821
ios::sync_with_stdio(0);
922
cin.tie(0);
10-
11-
}
23+
24+
cin >> n >> p >> q;
25+
cout << solve(n);
26+
}
27+
/*
28+
해시를 활용한 DP 구현입니다.
29+
재귀를 활용했으며,
30+
값을 이미 계산했다면 그 값을 반환합니다.
31+
*/

0 commit comments

Comments
 (0)
0