-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10971.cpp
More file actions
56 lines (46 loc) · 963 Bytes
/
10971.cpp
File metadata and controls
56 lines (46 loc) · 963 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
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int arr[10][10];
int n;
int solve(int start , int pos, int visited)
{
if(visited==(1 << n) -1)
{
return arr[pos][start];
}
int ret = 876554321;
for (int i = 0; i < n; ++i)
{
if(!(visited&(1 << i)) && arr[pos][i])
{
int tmp = arr[pos][i] + solve(start,i,visited|(1 << i));
if(tmp<ret) ret = tmp;
}
}
return ret;
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
cin>>arr[i][j];
if(arr[i][j]==0) arr[i][j] = 876554321;
}
}
int ans = 876554321;
for (int i = 0; i < n; ++i)
{
int temp = solve(i,i,1 << i);
if(ans>temp) ans = temp;
}
cout<<ans<<"\n";
return 0;
}