본문 바로가기
  • Let's study

백준45

[C++] 백준 2225번: 합분해 dp라는 건 금방 감이 왔고 N과 K가 만큼 더해야 하니까 2차원 배열을 써야겠다고 생각이 났다. dp 배열에서 행은 N, 열은 K를 저장한다고 볼 때 dp[3][3]을 구해보자. dp[1][1]=1, dp[1][2]=2, dp[1][3]=1; dp[2][1]=1, dp[2][2]=3, dp[2][3]=4; dp[3][1]=1, dp[3][2]=4, dp[3][3]=8; dp[2][2]=dp[1][1]+dp[1][2]이고 dp[3][3]=dp[2][1]+dp[2][2]+dp[2][3] 임을 볼 수 있다. #include #define MAX 1000000000 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0), c.. 2021. 9. 12.
[C++] 백준 2468번: 안전 영역 #include #include #include #include using namespace std; int arr[101][101]; bool visit[101][101]; int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 }; int n, height[101]; void dfs(int x, int y, int h) { visit[x][y] = true; for (int i = 0; i = 0 && nx = 0 && ny h) { dfs(nx, ny, h); } } } int main() { .. 2021. 9. 12.
[C++] 백준 20046번: Road Reconstruction #include #include #include #define MAX 1e9 using namespace std; int m, n; int dis[1001][1001]; int adj[1001][1001]; int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 }; int visit[1001][1001]; void dijkstra(int a, int b) { fill(&dis[0][0], &dis[1000][1001], MAX); priority_queue pq; if (adj[a][b] != -1) { dis[a][b] = adj[a][b]; pq.push({ -dis[a][b], {a,b} }); } while (!pq.empty()) { int c = -pq.top().f.. 2021. 9. 9.
[C++] 백준 6764번: Sounds fishy! 오타가 있는 문제입니다. 네 수가 모두 같을 때는 "Fish at Constant Depth"라고 출력해야 하고 적혀진 세 조건을 만족하지 못했을 때는 "No Fish"라고 출력해야 합니다.(No Fish에 . 을 빼야함) #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int arr[4]; int up = 0; int down = 0; int same = 0; for (int i = 0; i > arr[i]; } for (int i = 1; i arr[i - 1]) up++; else i.. 2021. 3. 13.
[C++] 백준 10799번: 쇠막대기 ')'가 입력될 때 이전 괄호가 '('이면 현재까지 저장된 '(' 개수를 더해주고 이전 괄호가 ')'라면 1을 더해준다. #include #include #include using namespace std; stack s; int main() { string str; cin >> str; int res = 0; for (int i = 0; i < str.size(); i++) { if (str[i] == '(') { s.push(str[i]); } else { s.pop(); if (str[i - 1] == '(') { res += s.size(); } else { res ++; } } } cout 2021. 2. 4.
[C++] 백준 16206번: 롤케이크 1. 10의 배수를 먼저 크기 순서대로 정렬한 후 나머지 숫자는 뒤에 붙인다. 2. 배열을 돌면서 10보다 크고 m>0일 동안 v[i]에서 10을 빼면서 카운트를 센다. 3. v[i]가 10인 경우를 따로 카운트 해준다. #include #include #include using namespace std; vectorv; vectorv2; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, a; cin >> n >> m; for (int i = 0; i > a; if (a % 10 == 0) v.push_back(a); else v2.push_back(a); } sort(v.begin().. 2021. 1. 23.