[BOJ] 17182 우주 탐사선

Time Lapse :25min 0sec

17182.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
#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
int g[10][10];
int v[1<<11][10];
int n, k;
void dfs(int bit, int cur, int cost) {
if(v[bit][cur] <= cost) return;
v[bit][cur] = cost;
if(bit + 1 == (1<<n)) return;
for(int i = 0; i < n; i++)
dfs(bit | (1 << i), i, cost + g[cur][i]);
}
int main() {
scanf("%d %d",&n,&k);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
scanf("%d",&g[i][j]);
memset(v,0x3f,sizeof(v));
dfs(1<<k,k,0);
int ans = 987654321;
for(int i = 0; i < n; i++)
ans = min(ans,v[(1<<n)-1][i]);
printf("%d",ans);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/09/05/PS/BOJ/17182/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.