-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnapsack_Packing.cpp
More file actions
69 lines (61 loc) · 1015 Bytes
/
Knapsack_Packing.cpp
File metadata and controls
69 lines (61 loc) · 1015 Bytes
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
map< lli, lli > numeros;
lli n;
cin>>n;
lli power = pow(2,n);
vector<lli> auxiliar(power);
for(lli i=0; i<power; i++)
{
cin>>auxiliar[i];
numeros[ auxiliar[i] ]++;
}
if(numeros[0]==0)
{
cout<<"impossible\n";
return 0;
}
sort(auxiliar.begin(), auxiliar.end());
for(lli i=1; i<power; i++)
{
if(numeros[ auxiliar[i] ] >0 )
{
for(lli j=i+1; j<power; j++)
{
if(numeros[ auxiliar[j] ] > 0)
{
numeros[ auxiliar[i] + auxiliar[j] ] --;
}
}
}
}
numeros[0]--;
vector<lli> answer;
for(auto x: numeros)
{
cout<<x.first<<" "<<x.second<<endl;
if(x.second>0)
{
for(lli i=0; i<x.second; i++)
{
//cout<<x.first<<endl;
answer.push_back(x.first);
}
}
}
if(answer.size()==n)
{
for(auto x:answer)
{
cout<<x<<endl;
}
}
else
{
cout<<"impossible\n";
}
return 0;
}