結果

問題 No.134 走れ!サブロー君
ユーザー yuustiyuusti
提出日時 2015-01-23 00:30:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 61,056 KB
実行使用メモリ 7,544 KB
最終ジャッジ日時 2023-09-05 03:55:20
合計ジャッジ時間 1,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,360 KB
testcase_01 AC 6 ms
7,380 KB
testcase_02 AC 6 ms
7,392 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 14 ms
7,480 KB
testcase_10 AC 6 ms
7,364 KB
testcase_11 AC 7 ms
7,488 KB
testcase_12 AC 6 ms
7,348 KB
testcase_13 AC 6 ms
7,432 KB
testcase_14 AC 6 ms
7,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 15;
double dp[N][1 << N];

double x[N], y[N], w[N];

const double INF = 1e18;
int n;

double dist(int i, int j){
	return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}

double calc(int i, int j, int w){
	return dist(i, j) * (w + 100) / 120;
}

double rec(int v, int vis){
	if (!v && vis) return vis + 1 == 1 << n ? 0 : INF;
	double &res = dp[v][vis];
	if (res >= -.5) return res;

	int wt = 0;
	for (int i = 0; i < n; ++i) if (~vis >> i & 1) wt += w[i];

	res = INF;
	for (int i = 0; i < n; ++i){
		if (vis >> i & 1) continue;
		res = min(res, rec(i, vis | (1 << i)) + calc(v, i, wt) + w[i]);
	}
	return res;
}


int main(){
	cout.setf(ios::fixed);
	cout.precision(100);

	cin >> x[0] >> y[0] >> n;
	++n;
	for (int i = 1; i < n; ++i) cin >> x[i] >> y[i] >> w[i];
	for (int i = 0; i < 1 << N; ++i) for (int j = 0; j < N; ++j) dp[j][i] = -1;

	cout << rec(0, 0) << endl;
}
0