[BOJ] 2629 양팔저울

Time Lapse :NONE

2629.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
int N, n, ball;
int arr[30];
int table[31][15001];
void init(int cur, int val){
if(cur>N) return;
if(table[cur][val]) return;
table[cur][val] = true;
init(cur+1,val+arr[cur]);
init(cur+1,val);
init(cur+1,val-arr[cur]>0?val-arr[cur]:arr[cur]-val);
}
int main(void){
scanf("%d",&N);
for(int i = 0; i < N; ++i)
scanf("%d",&arr[i]);
init(0,0);
scanf("%d",&n);
while(n--){
scanf("%d",&ball);
ball > 15000 ? printf("N ") : table[N][ball] ? printf("Y ") : printf("N ");
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2629/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.