Submission #00109


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
void Floyd_Warshall(vector< vector< int > >& graph){
for(int k = 0; k < graph.size(); k++){
for(int i = 0; i < graph.size(); i++){
for(int j = 0; j < graph.size(); j++){
graph[i][j] = min( graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
return ;
}
int main()
{
int N, M, S;
cin >> N >> M >> S;
vector< vector< int > > graph(N, vector< int >(N, INF));
--S;
for(int i = 0; i < M; i++) {
int A, B, C;
cin >> A >> B >> C;
--A, --B;
graph[A][B] = graph[B][A] = C;
}
Floyd_Warshall(graph);
vector< vector< int > > dp(1 << N, vector< int >(N, INF));
dp[0][S] = 0;
for(int i = 0; i < 1 << N; i++) {
for(int j = 0; j < N; j++) {
if(dp[i][j] >= INF) continue;
for(int k = 0; k < N; k++) {
if((i >> k) & 1) continue;
dp[i|(1 << k)][k] = min(dp[i|(1 << k)][k], dp[i][j] + graph[j][k]);
}
}
}
cout << dp[(1 << N) - 1][S] << endl;
}

ステータス

項目 データ
問題 0010 - クッキー
ユーザー名 ei1333
投稿日時 2015-05-22 16:55:39
言語 C++11
状態 Accepted
得点 35
ソースコード長 1059 Byte
最大実行時間 13 ms
最大メモリ使用量 768 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 10 ms 628 KB
1
cookies_input2.txt AC 13 ms 736 KB
2
cookies_input3.txt AC 12 ms 768 KB
3