-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathteamwork.cpp
39 lines (35 loc) · 818 Bytes
/
teamwork.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
# include <fstream>
# include <algorithm>
# define NR 500000
using namespace std;
ifstream f("teamwork.in");
ofstream g("teamwork.out");
int i,j,n,m,x,y,stop;
int maxx[NR], bit[NR], a[20][20];
void biti () {
for (i=1; i<=stop; ++i){
int VV=i;
while (VV) {
bit[i]+=VV%2;
VV/=2;
}
}
}
int main ()
{
f>>n;
for (i=1; i<=n; ++i)
for (j=1; j<=n; ++j)
f>>a[i][j];
// maxx[i] - maximul pe care il pot obtine folosind
// elevii bitii lui i, in biti[i] zile
stop=(1<<n)-1; biti ();
for (i=0; i<=stop; ++i) {
for (j=0; j<n; ++j)
if (! (i & (1<<j))){
maxx[i + (1<<j)]=max(maxx[i + (1<<j)], maxx[i] + a[j+1][bit[i]+1]);
}
}
g<<maxx[stop]<<"\n";
return 0;
}