結果

問題 No.134 走れ!サブロー君
ユーザー knewknowlknewknowl
提出日時 2015-02-10 19:26:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 915 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 62,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 18:03:12
合計ジャッジ時間 1,235 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;
int n;
double G[15][15];
double W[15];
double wsum;
double x[15],y[15];
double state[15][1<<15];

double dfs(int node,int bit,double w){
  if(bit==1) return G[0][node]*(wsum+100)/120.0;
  if(state[node][bit]) return state[node][bit];
  double ret = 1<<30;
  for(int j=1;j<=n;++j){
    if((bit>>j)&1){
      ret = min(ret,dfs(j,bit&(~(1<<j)),w+W[j])+W[j]+G[j][node]*(w+100)/120.0);
    }
  }
  return state[node][bit] = ret;
}

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

void init(){
  for(int i=0;i<=n;++i){
    for(int j=i+1;j<=n;++j){
      G[i][j] = G[j][i] = abs(x[i]-x[j])+abs(y[i]-y[j]);
    }
  }
  for(int i=1;i<=n;++i) wsum+=W[i];
}

int main(){
  input();
  init();
  printf("%.10lf\n",dfs(0,(1<<(n+1))-1,0));
  return 0;
}
0