結果

問題 No.134 走れ!サブロー君
ユーザー fiordfiord
提出日時 2015-08-18 23:32:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 890 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 165,336 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-22 18:03:50
合計ジャッジ時間 1,908 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
ld dp[1<<14][14];
ld weight[1<<14];
int main(){
	int sx,sy;	cin>>sx>>sy;
	int n;	cin>>n;
	vector<int> x(n),y(n);
	vector<double> w(n);
	for(int i=0;i<n;i++)	cin>>x[i]>>y[i]>>w[i];
	x.insert(x.begin(),sx);	y.insert(y.begin(),sy);	w.insert(w.begin(),0.0);
	n++;
	double sw=0;
	for(int i=0;i<n;i++)	sw+=w[i];
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i>>j)%2)	weight[i]+=w[j];
		}
		weight[i]=sw-weight[i];
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++)	dp[i][j]=(1<<30);
	}
	dp[0][0]=0;
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if(dp[i][j]==(1<<30))	continue;
			for(int k=0;k<n;k++){
				int next=(i|(1<<k));
				dp[next][k]=min(dp[next][k],dp[i][j]+(ld)(abs(x[j]-x[k])+abs(y[j]-y[k]))*(weight[i]+100)/120+w[k]);
			}
		}
	}
	printf("%.15lf\n",(double)dp[(1<<n)-1][0]);
	return 0;
}
0