-
Notifications
You must be signed in to change notification settings - Fork 0
/
1047-Zones.cpp
77 lines (72 loc) · 1.16 KB
/
1047-Zones.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
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
#include<cstdio>
#include<cstring>
using namespace std;
int m,n,c;
int t[30],ca[20],inside_ca[20];
int current,Max=0,best;
int count(int a)
{
int n = 0;
while(a!=0)
{
n++;
a-=(a&(-a));
}
return n;
}
int main()
{
int TC = 1;
while(scanf("%d %d",&m,&n),m)
{
Max = 0;
memset(inside_ca,0,sizeof(inside_ca));
for(int i=0;i<m;i++)
scanf("%d",&t[i]);
scanf("%d",&c);
for(int i=0;i<c;i++)
{
int x;
scanf("%d",&x);
for(int j=0;j<x;j++)
{
int p;
scanf("%d",&p);
inside_ca[i]|=1<<(p-1);
}
scanf("%d",&ca[i]);
}
for(int k=1;k<(1<<(m));k++)
if(count(k)==n)
{
//printf("%d\n",k);
int sum = 0;
for(int i=0;i<m;i++)
if(k&(1<<i))
{
//printf("%d ",i);
sum+=t[i];
}
for(int i=0;i<c;i++)
{
int tmp = inside_ca[i]&k;
if(tmp>1)
sum-=(count(tmp)-1)*ca[i];
}
//if(k==7) for(int i=0;i<c;i++)printf("%d ",area[i]);
if(sum>Max)
{
Max = sum;
best = k;
}
}
printf("Case Number %d\n",TC++);
printf("Number of Customers: %d\n",Max);
printf("Locations recommended:");
for(int i=0;i<m;i++)
if(best&(1<<i))
printf(" %d",i+1);
printf("\n\n");
}
return 0;
}