forked from oeddyo/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathholstein.cpp
More file actions
106 lines (94 loc) · 1.91 KB
/
holstein.cpp
File metadata and controls
106 lines (94 loc) · 1.91 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
ID: xieke.b1
PROG: holstein
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
ofstream fout("holstein.out");
ifstream fin ("holstein.in");
int N,V;
const int INF = 999999999;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define all(c) (c).begin(), (c).end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
map< pii, int> mymap;
const int MAXN = 30;
vi p[MAXN];
vi needs;
bool exceed(int s){
vi tmp(V,0);
for(int i=0; i<N; i++){
if( ((1<<i)&s) != 0){
for(int j=0; j<V; j++){
tmp[j]+=p[i][j];
}
}
}
/*
cout<<"now s is "<<s<<endl;
cout<<"needs is "<<endl;
for(int j=0; j<V; j++){
cout<<needs[j]<<" ";
}cout<<endl;
cout<<"tmp is "<<endl;
for(int j=0; j<V; j++){
cout<<tmp[j]<<" ";
}cout<<endl;
*/
for(int j=0; j<V; j++){
if(tmp[j]<needs[j]){
return false;
}
}
return true;
}
void work(){
int ans = INF;
int state = -1;
for(int s=0; s<(1<<N); s++){
int num = __builtin_popcount(s);
if(exceed(s) ){
//ans = min(ans, num);
if( ans>num){
ans = num;
state = s;
}
}
}
vi ans_v;
for(int i=0; i<N; i++){
if( (state&(1<<i)) !=0){
ans_v.push_back(i+1);
}
}
fout<<ans;
for(int i=0; i<ans_v.size(); i++){
fout<<" "<<ans_v[i];
}fout<<endl;
}
int main(){
fin>>V;
for(int i=0; i<V; i++){
int t;
fin>>t;
needs.push_back(t);
}
fin>>N;
for(int i=0; i<N; i++){
for(int j=0; j<V; j++){
int t;
fin>>t;
p[i].push_back(t);
}
}
work();
return 0;
}