전체 글(334)
-
[BOJ] 15894번 : 수학은 체육과목 입니다
1. problem : https://www.acmicpc.net/problem/15894 2. solution 1 :#include using namespace std;long long n;int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; cout 옆면을 옆으로 밀어버리고, 밑면은 밑으로 밀어버리고, 윗면은 위로 밀어버리면, 정사각형이라고 생각할 수 있다. 설명참조 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x12/solutions/15894.cpp basic-algo-lecture/0x12/solutions/15894.cpp at master · encryp..
2024.09.26 -
[BOJ] 11052번 : 카드 구매하기
1. problem : https://www.acmicpc.net/problem/11052 2. solution 1 :#include using namespace std;int t; int a[1005]; int d[1005]; // i일때 최댓값 int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> t; for (int i = 1; i > a[i]; d[0] = 0; for (int i = 1; i dp를 이용해 풀었다. 따라서 세 가지 스텝을 따른다. 1. 테이블을 정의한다. d[i] = i개를 살 때, 최대 금액이다. 2. 점화식을 작성한다. d[i] = max(d [i] , d [i-j] + a [j])) 3. 초기값을 설정한다. d[0]..
2024.09.26 -
[BOJ] 2302번 : 극장 좌석
1. problem : https://www.acmicpc.net/problem/2302 2. solution 1 :#include using namespace std;int d[42]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); d[0] = 1, d[1] = 1, d[2] = 2; for (int i = 3; i > n; cin >> m; int ans = 1; int start_idx = 1; while (m--) { int x; cin >> x; ans *= d[x - start_idx]; start_idx = x + 1; } ans *= d[n - start_idx + 1]; cout dp를 이용해 풀었다. 따라서, 세 가지 스텝..
2024.09.25 -
[BOJ] 6064번 : 카잉 달력
1. problem : https://www.acmicpc.net/problem/6064 2. solution 1 :#include using namespace std;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 solve(int m, int n, int x, int y) { if (x == m) x = 0; if (y == n) y = 0; int l = lcm(m, n); for (int i = x; i > t; while (t--) { cin >> m >> n >> x >> y; cout source code 출처 ..
2024.09.25 -
[BOJ] 11051번 : 이항 계수 2
1. problem : https://www.acmicpc.net/problem/11051 2. solution 1 :#include using namespace std;int n, k; int d[1005][1005]; const int val = 10007;int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 0; i 조합의 성질을 이용하여, nCk = n-1Ck-1 + n-1Ck 풀었다. 이 성질을 이용하여 dp를 사용했다. 따라서 세 가지 스텝을 따른다. 1. 테이블을 정의한다. d[i][j]는 iCj를 나타낸다. 2. 점화식을 작성한다. 조합의 성질을 이용하여, d [i][j] = d [i-1][j-1..
2024.09.25 -
[BOJ] 11050번 : 이항 계수 1
1. problem : https://www.acmicpc.net/problem/11050 2. solution 1 :#include using namespace std;int n, k; int factorial(int a) { if (a == 0 || a == 1) return 1; return a * factorial(a - 1);}int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; int ans = factorial(n) / (factorial(n - k) * factorial(k)); cout factorial 함수를 재귀적으로 구현했다. 3. solution 2 :// Authored by : Baaaaaaaaaaar..
2024.09.24