[BOJ]21745 눈덩이 굴리기

강동현·2024년 2월 2일
0

코딩테스트

목록 보기
85/111
  • sol: 백트래킹
    • 눈덩이를 굴리는 위치는 0
    • 1 - N까지 눈덩이를 굴릴 수 있다.
#include <bits/stdc++.h>
using namespace std;
int N, M, tmp, ms = -1;
vector<int> yards;
void DFS(int cur, int size, int cnt){
    if(cur == N || cnt == M) {
        ms = max(ms, size);
        return;
    }
    if(cur < N) DFS(cur+1, size+yards[cur+1], cnt+1);
    if(cur+1 < N) DFS(cur+2, size/2+yards[cur+2], cnt+1);
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> N >> M;
    yards.push_back(0);
    for(int i = 0; i < N; ++i){
        cin >> tmp;
        yards.push_back(tmp);
    }
    DFS(0, 1, 0);
    cout << ms;
    return 0;
}
profile
GAME DESIGN & CLIENT PROGRAMMING

0개의 댓글