-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNet.cpp
More file actions
57 lines (44 loc) · 855 Bytes
/
Net.cpp
File metadata and controls
57 lines (44 loc) · 855 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
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
int size;
signed long net[20][20];
bool solution[20];
signed long maxTraffic = 0;
void Compute(){
signed long traffic = 0;
for(int i = 0; i < size; i++){
if(solution[i])
for(int j = 0; j < size; j++)
if(!solution[j])
traffic += net[i][j];
}
if(maxTraffic < traffic)
maxTraffic = traffic;
}
void FindSolution(int index){
if(index > size - 2)
return;
if(solution[index]){
solution[index] = false;
FindSolution(index + 1);
return;
}
else
solution[index] = true;
Compute();
FindSolution(0);
}
int main(){
ifstream In("input.txt");
ofstream Out("output.txt");
In >> size;
for(int i = 0; i < size; i++)
for(int j = 0; j < size; j++)
In >> net[i][j];
In.close();
FindSolution(0);
Out << maxTraffic;
Out.close();
}