結果

問題 No.134 走れ!サブロー君
ユーザー yuustiyuusti
提出日時 2015-01-23 00:32:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 947 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 58,456 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-22 18:00:52
合計ジャッジ時間 1,110 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,424 KB
testcase_01 AC 5 ms
7,552 KB
testcase_02 AC 6 ms
7,296 KB
testcase_03 AC 6 ms
7,424 KB
testcase_04 AC 5 ms
7,296 KB
testcase_05 AC 6 ms
7,424 KB
testcase_06 AC 8 ms
7,424 KB
testcase_07 AC 8 ms
7,296 KB
testcase_08 AC 13 ms
7,552 KB
testcase_09 AC 13 ms
7,424 KB
testcase_10 AC 6 ms
7,296 KB
testcase_11 AC 6 ms
7,424 KB
testcase_12 AC 6 ms
7,424 KB
testcase_13 AC 6 ms
7,296 KB
testcase_14 AC 6 ms
7,424 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, double 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;

	double 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