結果
| 問題 |
No.134 走れ!サブロー君
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-16 05:12:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 1,117 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 36,192 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 17:14:06 |
| 合計ジャッジ時間 | 806 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%lf %lf", &X[0], &Y[0]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:40:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%lf %lf %lf", X+i, Y+i, W+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
double dp[1<<13][14], weight[1<<13];
double X[14], Y[14], W[14];
int N;
double dist(int i, int j){
return std::abs(X[i] - X[j]) + std::abs(Y[i] - Y[j]);
}
double rec(int state, int index){
if(state == 0){
return 100.0 / 120 * dist(0, index);
}
if(dp[state][index] > 0.0){return dp[state][index];}
double res = 1e20;
for(int i=0;i<N;i++){
if(!(state >> i & 1)){continue;}
res = std::min(res, (weight[state] + 100) / 120 * dist(index, i+1) + W[i+1] + rec(state & ~(1 << i), i+1));
}
return dp[state][index] = res;
}
int main(){
scanf("%lf %lf", &X[0], &Y[0]);
scanf("%d", &N);
for(int i=0;i<1<<N;i++){
for(int j=0;j<=N;j++){
dp[i][j] = -1.0;
}
}
for(int i=1;i<=N;i++){
scanf("%lf %lf %lf", X+i, Y+i, W+i);
}
for(int i=0;i<1<<N;i++){
double sum = 0.0;
for(int j=0;j<N;j++){
if(!(i >> j & 1)){continue;}
sum += W[j+1];
}
weight[i] = sum;
}
printf("%.6f\n", rec((1<<N)-1, 0));
}
tottoripaper