Algorithm(218)
-
[BOJ] 1654번 : 랜선 자르기
1. problem : https://www.acmicpc.net/problem/1654 2. solution 1 :#include using namespace std;int k, n;int nums[10005];typedef long long ll;int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> k >> n; for (int i = 0; i > nums[i]; ll left = 1ll; ll right = *max_element(nums, nums + k); ll answer = 0; while (left = n) { left = mid + 1; answer = mid; } } cout
2024.09.01 -
[BOJ] 2193번 : 이친수
1. problem : https://www.acmicpc.net/problem/2193 2. solution 1 :#include using namespace std;int n;long long d[95]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; d[1] = 1, d[2] = 1; for (int i = 3; i 3. solution 2 :// Authored by : Hot6Mania// Co-authored by : -// http://boj.kr/62b94c1ad9254f87a1f6e37323f2c5bf#include using namespace std;typedef long long ll;int n;ll d[100][..
2024.09.01 -
[BOJ] 11727번 : 2 x n 타일링 2
1. problem : https://www.acmicpc.net/problem/11727 2. solution 1 :#include using namespace std;int n;int d[1005]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); d[1] = 1; d[2] = 3; for (int i = 3; i > n; cout 3. solution 2 :#include int dp[1001];int rec(int x){ if (x == 1) return 1; if (x == 2) return 3; if (dp[x] != 0) { return dp[x]; } return dp[x] = ( rec(x-1) + 2 * rec(x-2) ) % 1..
2024.09.01 -
[BOJ] 1932번 : 정수 삼각형
1. problem : https://www.acmicpc.net/problem/1932 2. solution 1 :#include using namespace std;int n;int d[505][505]; int trees[505][505]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; int depth = 0; for (int i = 1; i > trees[i][j]; // 각 층의 몇번째 가지인지 표현; } d[1][1] = trees[1][1], d[2][1] = trees[2][1] + d[1][1], d[2][2] = trees[2][2] + d[1][1]; for (int i = 3; i 3. solution 2..
2024.09.01 -
[BOJ] 1003번 : 피보나치 함수
1. problem : https://www.acmicpc.net/problem/1003 2. solution 1 :#include using namespace std;int t; vector> d(42,{0,0}); // {0 cnt, 1 cnt};int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { int n; cin >> n; d[0] = { 1,0 }, d[1] = { 0,1 }; for (int i = 2; i 3. solution 2 :// Authored by : heheHwang// Co-authored by : -// http://boj.kr/0a669ebf1000436b94e3067b..
2024.09.01 -
[BOJ] 12852번 : 1로 만들기 2
1. problem : https://www.acmicpc.net/problem/12852 2. solution 1 :#include using namespace std;int n;int d[1000005]; int pre[1000005]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; d[1] = 0; for (int i = 2; i d[i/2] + 1) { d[i] = min(d[i], d[i / 2] + 1); pre[i] = i / 2; } if (i % 3 == 0 && d[i] > d[i/3] + 1) { d[i] = min(d[i], d[i / 3] + 1); pre[i] = i / 3; } } co..
2024.08.31