結果

問題 No.134 走れ!サブロー君
ユーザー HachimoriHachimori
提出日時 2015-01-22 23:46:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,243 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 56,592 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-22 18:00:25
合計ジャッジ時間 1,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,504 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 4 ms
5,504 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 10 ms
5,504 KB
testcase_08 AC 19 ms
5,504 KB
testcase_09 AC 19 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0