結果

問題 No.134 走れ!サブロー君
ユーザー fiordfiord
提出日時 2015-08-18 23:12:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,084 bytes
コンパイル時間 1,221 ms
コンパイル使用メモリ 149,528 KB
実行使用メモリ 4,616 KB
最終ジャッジ日時 2023-09-25 12:56:19
合計ジャッジ時間 2,587 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
double dp[1<<14][14];
double 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];
	int 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);
	}
	for(int i=0;i<n;i++){
		dp[(1<<i)][i]=(double)(abs(sx-x[i])+abs(sy-y[i]))*(sw+100)/120+w[i];
	}
	for(int i=1;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i>>j)%2==0)	continue;
			cout<<j<<" "<<dp[i][j]<<" ";
			for(int k=0;k<n;k++){
				if((i>>k)%2)	cout<<k<<" ";
			}
			cout<<endl;
			for(int k=0;k<n;k++){
				int next=(i|(1<<k));
				dp[next][k]=min(dp[next][k],dp[i][j]+(double)(abs(x[j]-x[k])+abs(y[j]-y[k]))*(weight[i]+100)/120+w[k]);
			}
		}
	}
	double ans=(1<<30);
	for(int i=0;i<n;i++){
		ans=min(ans,dp[(1<<n)-1][i]+(double)(abs(x[i]-sx)+abs(y[i]-sy))*100/120);
	}
	printf("%.15lf\n",ans);
	return 0;
}
0