Submission #47742


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m, s;
int graph[16][16];
int dp[16][1<<16];
int dfs ( int pos, int bit ) {
bool res = true;
for ( int i = 0; i < n; i++ ) {
res &= (bit>>i)&1;
}
if ( res ) return graph[pos][0];
if ( ~dp[pos][bit] ) return dp[pos][bit];
int rec = INF;
for ( int i = 0; i < n; i++ ) {
if ( pos == i ) continue;
if ( bit & ( 1 << i ) ) continue;
rec = min ( rec, dfs ( i, bit|(1<<i) ) + graph[pos][i] );
}
return dp[pos][bit] = rec;
}
signed main() {
memset(graph, 0x3f, sizeof(graph));
scanf("%d %d %d", &n, &m, &s);
for ( int i = 0; i < m; i++ ) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
a--;
b--;
graph[a][b] = c;
graph[b][a] = c;
}
for ( int k = 0; k < n; k++ ) {
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < n; j++ ) {
graph[i][j] = min ( graph[i][j], graph[i][k] + graph[k][j] );
}
}
}
memset(dp, -1, sizeof(dp));
printf("%d\n", dfs(0, 1));
return 0;
}

ステータス

項目 データ
問題 0010 - クッキー
ユーザー名 r1825
投稿日時 2019-03-12 10:25:26
言語 C++
状態 Accepted
得点 35
ソースコード長 1196 Byte
最大実行時間 122 ms
最大メモリ使用量 4796 KB

セット

セット 得点 Cases
1 小課題1 5 / 5 cookies_input1.txt
2 小課題2 10 / 10 cookies_input2.txt
3 小課題3 20 / 20 cookies_input3.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
cookies_input1.txt AC 122 ms 4700 KB
1
cookies_input2.txt AC 29 ms 4796 KB
2
cookies_input3.txt AC 32 ms 4644 KB
3