-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathzebunghil.cpp
45 lines (37 loc) · 1.01 KB
/
zebunghil.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
# include <fstream>
# include <algorithm>
# define NR 1000005
using namespace std;
ifstream f("zebughil.in");
ofstream g("zebughil.out");
struct elem {
int X, C;
}a[NR];
int i,j,n,m,x,y,stop,G,antC,antX,nou;
int nr[1000];
int main ()
{
for (int t=1; t<=3; ++t) {
f>>n>>G;
for (i=1; i<=n; ++i)
f>>nr[i];
stop=(1<<(n+1))-2;
for (i=1; i<=stop; ++i) {
a[i].C=n+1; a[i].X=0;
for (j=1; j<=n; ++j)
if ((1<<j) & i) { // daca se afla in configuratie
antC=a[i-(1<<j)].C; antX=a[i-(1<<j)].X;
int ok=0;
if (antX + nr[j] > G) ok=1;
if (ok==1) nou=nr[j];
else nou=antX + nr[j];
if (antC + ok < a[i].C || (antC + ok == a[i].C && nou<a[i].X)) {
a[i].C=antC+ok;
a[i].X=nou;
}
}
}
g<<1 + a[stop].C<<"\n";
}
return 0;
}