結果
| 問題 | No.134 走れ!サブロー君 |
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-16 05:12:23 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 1,117 bytes |
| 記録 | |
| コンパイル時間 | 229 ms |
| コンパイル使用メモリ | 53,504 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-02 03:41:10 |
| 合計ジャッジ時間 | 1,333 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#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