[BOJ] 16938 캠프 준비

Time Lapse :16min 15sec

16938.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
int ans, N, X, L, R;
int arr[15];
bool vi[1<<16];
void dfs(int min, int max, int sum, int q, int n, int v) {
if(max - min >= X && q >= 2 && L <= sum && sum <= R && !vi[v])
vi[v] = ++ans;

if(n >= N || sum > R) return;
dfs(min,max,sum,q,n + 1, v);
dfs(min > arr[n] ? arr[n] : min, max > arr[n] ? max : arr[n], sum + arr[n], q + 1, n + 1, v | 1<<(n+1));
}

int main(void) {
scanf("%d %d %d %d",&N, &L, &R, &X);
for(int i = 0; i < N; ++i)
scanf("%d",&arr[i]);
dfs(987654321, -987654321, 0, 0, 0, 0);
printf("%d",ans);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/25/PS/BOJ/16938/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.