結果
| 問題 | No.134 走れ!サブロー君 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-10-17 15:16:34 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 5,000 ms | 
| コード長 | 1,203 bytes | 
| コンパイル時間 | 828 ms | 
| コンパイル使用メモリ | 77,120 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-24 13:09:37 | 
| 合計ジャッジ時間 | 1,647 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cfloat>
#include<cmath>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double x, y;
    int n;
    cin >> x >> y >> n;
    double X[n], Y[n], W[n], dp[n][1<<n], sum = 0;
    for(int i = 0; i < n; i++){
        cin >> X[i] >> Y[i] >> W[i];
        sum += W[i];
        for(int j = 0; j < 1<<n; j++)   dp[i][j] = DBL_MAX;
    }
    for(int i = 0; i < n; i++){
        dp[i][1<<i] = (abs(X[i]-x)+abs(Y[i]-y))*(sum+100)/120;
    }  
    for(int s = 0; s < 1<<n; s++){
        double tmps = sum;
        for(int i = 0; i < n; i++){
            if((s>>i)&1)    tmps -= W[i];
        }
        for(int i = 0; i < n; i++){
            if(((s>>i)&1) == 0)    continue;
            for(int j = 0; j < n; j++){
                if((s>>j)&1)    continue;
                dp[j][s|(1<<j)] = min(dp[j][s|(1<<j)], dp[i][s]+(abs(X[j]-X[i])+abs(Y[j]-Y[i]))*(tmps+100)/120);
            }
        }
    }
    double ans = DBL_MAX;
    for(int i = 0; i < n; i++){
        ans = min(ans, dp[i][(1<<n)-1]+(abs(X[i]-x)+abs(Y[i]-y))*100/120);
    }
    cout << fixed << setprecision(12) << ans + sum << endl;
    return 0;
}
            
            
            
        