Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- XR Interaction Toolkit
- 투 포인터
- ue5
- 유니온 파인드
- 백트래킹
- 백준
- 수학
- Team Fortress 2
- 우선순위 큐
- 다이나믹 프로그래밍
- DFS
- 다익스트라
- 그래프
- Unreal Engine 5
- VR
- 유니티
- 재귀
- 스택
- BFS
- 브루트포스
- 누적 합
- 시뮬레이션
- 정렬
- 그리디 알고리즘
- 알고리즘
- c++
- 구현
- 트리
- 자료구조
- 문자열
Archives
- Today
- Total
1일1알
백준 21735번 눈덩이 굴리기 C++ 본문
https://www.acmicpc.net/problem/21735
21735번: 눈덩이 굴리기
눈송이들이 많은 동네인 숙명여대 앞마당에서 눈사람 만들기 대회를 연다. 앞마당의 길이는 $N$이고 위치 $1$부터 위치 $N$ 까지만 눈이 쌓여있다. 위치 $i$에 눈이 $a_i$만큼 쌓여있다. 대회 규칙은
www.acmicpc.net
백트래킹
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
vector<int> v(101, 0);
int ans = 0;
void BT(int idx, int cnt, int _size) {
if (idx >= n || cnt == m) {
ans = max(ans, _size);
return;
}
BT(idx + 1, cnt + 1, _size + v[idx + 1]);
BT(idx + 2, cnt + 1, _size / 2 + v[idx + 2]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> v[i];
BT(0, 0, 1);
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 1448번 삼각형 만들기 C++ (0) | 2023.04.26 |
---|---|
백준 20006번 랭킹전 대기열 C++ (0) | 2023.04.25 |
백준 19949번 영재의 시험 C++ (0) | 2023.04.21 |
백준 5557번 1학년 C++ (1) | 2023.04.20 |
백준 16564번 히오스 프로게이머 C++ (0) | 2023.04.16 |