結果

問題 No.134 走れ!サブロー君
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-10-21 15:43:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 1,496 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 63,544 KB
実行使用メモリ 167,680 KB
最終ジャッジ日時 2024-05-02 22:00:53
合計ジャッジ時間 3,344 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
167,424 KB
testcase_01 AC 119 ms
167,424 KB
testcase_02 AC 121 ms
167,424 KB
testcase_03 AC 120 ms
167,424 KB
testcase_04 AC 121 ms
167,552 KB
testcase_05 AC 121 ms
167,424 KB
testcase_06 AC 124 ms
167,424 KB
testcase_07 AC 127 ms
167,424 KB
testcase_08 AC 132 ms
167,680 KB
testcase_09 AC 131 ms
167,552 KB
testcase_10 AC 120 ms
167,424 KB
testcase_11 AC 120 ms
167,424 KB
testcase_12 AC 120 ms
167,552 KB
testcase_13 AC 120 ms
167,424 KB
testcase_14 AC 121 ms
167,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;

int x[20], y[20];
double w[20];
int dist[20][20];
//dp[mask][i] := mask集合を巡って、iにいるときの最小コスト
double dp[(1 << 20)][20];
//weight[maks] := mask集合の時の荷物の重さ
double weight[(1 << 20)];

int main(void){
	cin >> x[0] >> y[0];
	w[0] = 0.0;
	int n; cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> x[i] >> y[i] >> w[i];
	}

	rep(i, n + 1)rep(j, n + 1){
		int len = abs(x[i] - x[j]) + abs(y[i] - y[j]);
		dist[i][j] = len;
	}

	//前計算
	for (int mask = 0; mask < (1 << (n + 1)); ++mask)
	{
		double tmp = 0;
		for (int i = 0; i < n + 1; ++i)
		{
			if((mask & (1 << i)) == 0){
				tmp += w[i];
			}
		}
		weight[mask] = tmp;
	}

	rep(i, (1 << 20))rep(j, 20) dp[i][j] = INF;
	dp[0][0] = 0;
	for (int mask = 0; mask < (1 << (n + 1)); ++mask)
	{
		for (int i = 0; i < n + 1; ++i)//現在時点
		{
			for (int p = 0; p < n + 1; ++p)//次に行くところ
			{
				if((mask & (1 << p)) == 0){//pをまだ訪れていない
					double cost = dist[i][p] * (double)((weight[mask] + 100.0) / 120.0);
					dp[mask | (1 << p)][p]
					= min(dp[mask | (1 << p)][p], dp[mask][i] + cost);
				}
			}
		}
	}
	double ret = 0;
	for (int i = 0; i < n + 1; ++i){
		ret += w[i];
	}
	printf("%.9f\n", dp[(1 << (n + 1)) - 1][0] + ret);
	return 0;
}
0