-
Notifications
You must be signed in to change notification settings - Fork 0
/
C - Synthetic Kadomatsu.cpp
50 lines (48 loc) · 1.27 KB
/
C - Synthetic Kadomatsu.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <fstream>
#include <string>
#include <iostream>
#include <bitset>
#include <math.h>
#include <algorithm>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
long long n, a, b, c;
int arr[8];
long long answer = 10000000;
void rec(int cur, int cura, int curb, int curc, int curm){
if (cur == n){
if (cura != 0 && curb != 0 && curc != 0){
answer = min(answer, curm + abs(a - cura) + abs(b - curb) + abs(c - curc));
}
}
else{
if (cura == 0){
rec(cur + 1, cura + arr[cur], curb, curc, curm);
}
else{
rec(cur + 1, cura + arr[cur], curb, curc, curm + 10);
}
if (curb == 0){
rec(cur + 1, cura, curb + arr[cur], curc, curm);
}
else{
rec(cur + 1, cura, curb + arr[cur], curc, curm + 10);
}
if (curc == 0){
rec(cur + 1, cura, curb, curc + arr[cur], curm);
}
else{
rec(cur + 1, cura, curb, curc + arr[cur], curm + 10);
}
rec(cur + 1, cura, curb, curc, curm);
}
}
int main(){
cin >> n >> a >> b >> c;
for (int x = 0; x < n; x++){
cin >> arr[x];
}
rec(0,0,0,0,0);
cout << answer << "\n";
}