Algorithm(218)
-
[BOJ] 9657번 : 돌 게임 3
1. problem : https://www.acmicpc.net/problem/9657 2. solution 1 :#include using namespace std;vector winners = { "SK","CY" };int n; vector rocks = { 1,3,4 }; int d[1005]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; d[1] = 0, d[2] = 1, d[3] = 0, d[4] = 0; for (int i = 5; i source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/9657.c..
2024.10.06 -
[BOJ] 1520번 : 내리막 길
1. problem : https://www.acmicpc.net/problem/1520 2. solution 1 :#include using namespace std;int dx[4] = { 0,1,0,-1 };int dy[4] = { 1,0,-1,0 }; int n, m; int a[505][505], d[505][505]; int dp(int x, int y) { if (d[x][y] != -1) return d[x][y]; if (x == n - 1 && y == m - 1) return 1; int& ret = d[x][y]; ret = 0; for (int dir = 0; dir = n || ny = m) continue; if (a[x][y] > a[nx][ny]) ret += dp(..
2024.10.05 -
[BOJ] 1476번 : 날짜 계산
1. problem : https://www.acmicpc.net/problem/1476 2. solution 1:#include using namespace std;int e, s, m; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}int lcm(int a, int b) { return a / gcd(a, b) * b;}int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> e >> s >> m; e--, s--, m--; int i = e; while (i % 28 != s) i += 15; int l = lcm(15, 28); while (i % 19 != m..
2024.10.04 -
[BOJ] 2133번: 타일 채우기
1. problem : https://www.acmicpc.net/problem/2133 2. solution 1 :#include using namespace std;int d[33];int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; d[0] = 1, d[2] = 3; for (int i = 3; i = 0; j -= 2) { d[i] += d[j] * 2; } } cout source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/2133.cpp basic-algo-lecture/0x10/solutions..
2024.10.03 -
[BOJ] 9613번 : GCD 합
1. problem : https://www.acmicpc.net/problem/9613 2. solution 1 :#include using namespace std;int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}int main(void) { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; long long ans = 0; int a[105]; for (int i = 0; i > a[i]; for (int i = 0; i gcd를 직접 구현하여, 문제를 풀었다. ans는 100억이 될 수 있기 때문에, l..
2024.10.03 -
[BOJ] 2294번 : 동전 2
1. problem : https://www.acmicpc.net/problem/2294 2. solution 1 :#include using namespace std;const int val = 10005;int coins[val]; int d[val];int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i > coins[i]; d[0] = 0; for (int i = 1; i i) continue; if (d[i-coins[c]] == 10001) continue; d[i] = min(d[i], d[i - coins[c]] + 1); } } if (d[k] == 1..
2024.10.03