結果
| 問題 | No.134 走れ!サブロー君 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-01-22 23:46:53 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 19 ms / 5,000 ms | 
| コード長 | 1,243 bytes | 
| コンパイル時間 | 380 ms | 
| コンパイル使用メモリ | 55,548 KB | 
| 実行使用メモリ | 5,504 KB | 
| 最終ジャッジ日時 | 2024-10-14 17:10:51 | 
| 合計ジャッジ時間 | 1,006 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int NUM = 14;
const int BUF = 1 << NUM;
const int INF = 1 << 30;
int N;
int x[NUM], y[NUM];
double w[NUM];
void read() {
    cin >> x[0] >> y[0];
    w[0] = 0;
    
    cin >> N;
    for (int i = 1; i <= N; ++i)
        cin >> x[i] >> y[i] >> w[i];
    
    ++N;
}
double calc(int s, int t, double totalW) {
    int dist = abs(x[s] - x[t]) + abs(y[s] - y[t]);
    return dist * (totalW + 100) / 120.0;
}
double rec(int pos, int mask, double dp[NUM][BUF]) {
    if (mask == (1 << N) - 1) return calc(pos, 0, 0);
    double &ret = dp[pos][mask];
    if (ret > -0.5) return ret;
    
    ret = INF;
    
    double totalW = 0;
    for (int i = 0; i < N; ++i)
        if (!(mask & (1 << i)))
            totalW += w[i];
    
    for (int i = 0; i < N; ++i) {
        if (mask & (1 << i))
            continue;
        ret = min(ret, rec(i, mask | (1 << i), dp) + w[i] + calc(pos, i, totalW));
    }
    return ret;
}
void work() {
    double dp[NUM][BUF];
    for (int i = 0; i < NUM; ++i)
        for (int j = 0; j < BUF; ++j)
            dp[i][j] = -1;
    
    printf("%.10lf\n", rec(0, 0, dp));
}
int main() {
    read();
    work();
    return 0;
}
            
            
            
        