Submission #16092
ソースコード
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<set> int n,s; int con[11][11]; int f( int perm, int len, int deep, int p){ if (deep==n){ return len+con[s][p]; } else { int re=-1; for ( int p2=0;p2<n;p2++){ int b=1<<p2; if ((perm&b)==0){ int re2=f(perm|b,len+con[p][p2],deep+1,p2); if ((re==-1)||(re>re2)){ re=re2; } } } return re; } } int main(){ int m; scanf ( "%d %d %d" ,&n,&m,&s); s--; for ( int i=0;i<n;i++){ for ( int j=0;j<n;j++){ con[i][j]=-1; } } for ( int i=0;i<m;i++){ int a,b,c; scanf ( "%d %d %d" ,&a,&b,&c); a--; b--; con[a][b]=c; con[b][a]=c; } for ( int k=0;k<n;k++){ for ( int i=0;i<n;i++){ for ( int j=0;j<n;j++){ if ((con[i][k]==-1)||(con[k][j]==-1)) continue ; int t=con[i][k]+con[k][j]; if ((con[i][j]==-1)||(con[i][j]>t)){ con[i][j]=t; } } } } printf ( "%d\n" ,f(1<<s,0,1,s)); } |
ステータス
項目 | データ |
---|---|
問題 | 0010 - クッキー |
ユーザー名 | sinapusu2002 |
投稿日時 | 2017-04-30 18:21:24 |
言語 | C++11 |
状態 | Accepted |
得点 | 35 |
ソースコード長 | 907 Byte |
最大実行時間 | 34 ms |
最大メモリ使用量 | 480 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 | 30 ms | 480 KB |
1
|
||
cookies_input2.txt | AC | 34 ms | 472 KB |
2
|
||
cookies_input3.txt | AC | 28 ms | 464 KB |
3
|