From 67f6b27deed150f635c9cfec63d0fa0b329eb742 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Mon, 5 Aug 2024 03:32:36 +0900 Subject: [PATCH] week3 --- boj/darr/1245.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++ boj/darr/20167.cpp | 51 +++++++++++++++++++++++++++++++++++++++++ boj/darr/4889.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ boj/darr/6236.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+) create mode 100644 boj/darr/1245.cpp create mode 100644 boj/darr/20167.cpp create mode 100644 boj/darr/4889.cpp create mode 100644 boj/darr/6236.cpp diff --git a/boj/darr/1245.cpp b/boj/darr/1245.cpp new file mode 100644 index 0000000..27238b6 --- /dev/null +++ b/boj/darr/1245.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +using namespace std; + +int n,m; +int dx[8] = {0, 0, -1, 1, -1, 1, -1, 1}; +int dy[8] = {-1, 1, 0, 0, -1, 1, 1, -1}; +int mountain[101][71]; +bool check[101][71]; + +bool checkIsMountainBud(int x, int y) { + bool flag = true; + + for(int i=0; i<8; i++) { + int positionX = x + dx[i]; + int positionY = y + dy[i]; + if(min(positionX, positionY) < 0 || positionX >= n || positionY >= m) continue; + if(mountain[positionX][positionY] > mountain[x][y]) flag = false; + if(check[positionX][positionY]) continue; + if(mountain[positionX][positionY] == mountain[x][y]) { + check[positionX][positionY] = true; + flag = checkIsMountainBud(positionX, positionY) ? flag : false; + } + } + + return flag; +} + +int main() { + cin>>n>>m; + + int answer = 0; + + for(int i=0; i>mountain[i][j]; + } + } + + for(int i=0; i +#include +#include + +using namespace std; + +int n, k; +int answer = 0; +int energy[21]; + +void dfs(int process, vector vec) { + if(process == n) { + int total = 0; + int sum = 0; + + for(int i=0; i= k) { + total += sum - k; + sum = 0; + } + } + } + total += max(0, sum - k); + answer = max(answer, total); + + return; + } + vector vec2(vec); + vec.push_back(-1); + vec2.push_back(energy[process]); + dfs(process + 1, vec); + dfs(process + 1, vec2); +} + +int main() { + cin>>n>>k; + + for(int i=0; i>energy[i]; + } + + vector vec; + dfs(0, vec); + + cout< +#include + +using namespace std; + +int main() { + int number = 1; + + while(1) { + int moveCount = 0; + string s; + cin>>s; + if(s[0] == '-') break; + + stack stack; + for(int i=0; i +#include + +using namespace std; + +int n, m; + +bool isValid(int amount[], int n, int m, int midAmount) { + int count = 1; // 첫 번째 인출 + int currentAmount = midAmount; + + for (int i = 0; i < n; i++) { + if (currentAmount >= amount[i]) { + currentAmount -= amount[i]; + } else { + count++; + currentAmount = midAmount - amount[i]; + if (currentAmount < 0) return false; // 인출 금액이 하루 지출보다 작다면 불가능 + } + } + return count <= m; +} + +int main() { + cin >> n >> m; + int amount[n]; + int maxAmount = 0; + int sumAmount = 0; + + for (int i = 0; i < n; i++) { + cin >> amount[i]; + maxAmount = max(amount[i], maxAmount); + sumAmount += amount[i]; + } + + int minAmount = maxAmount; + int answer = sumAmount; + + while (minAmount <= sumAmount) { + int mid = (minAmount + sumAmount) / 2; + + if (isValid(amount, n, m, mid)) { + answer = mid; + sumAmount = mid - 1; + } else { + minAmount = mid + 1; + } + } + + cout << answer << endl; + return 0; +}