結果
| 問題 | No.134 走れ!サブロー君 | 
| コンテスト | |
| ユーザー |  htensai | 
| 提出日時 | 2020-02-10 10:05:45 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 98 ms / 5,000 ms | 
| コード長 | 1,830 bytes | 
| コンパイル時間 | 2,634 ms | 
| コンパイル使用メモリ | 77,864 KB | 
| 実行使用メモリ | 50,528 KB | 
| 最終ジャッジ日時 | 2024-10-01 06:15:45 | 
| 合計ジャッジ時間 | 4,190 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
import java.util.*;
import java.io.*;
public class Main {
    static int x0;
    static int y0;
    static int n;
    static Place[] places;
    static double[][] dp;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        x0 = Integer.parseInt(first[0]);
        y0 = Integer.parseInt(first[1]);
        n = Integer.parseInt(br.readLine());
        places = new Place[n];
        for (int i = 0; i < n; i++) {
            places[i] = new Place(br.readLine().split(" ", 3));
        }
        dp = new double[1 << n][n + 1];
        System.out.println(dfw((1 << n) - 1, n,  x0, y0));
   }
   
   static double dfw(int key, int idx, int x, int y) {
       if (key == 0) {
           return (Math.abs(x - x0) + Math.abs(y - y0)) * 100.0 / 120.0;
       }
       if (dp[key][idx] != 0.0) {
           return dp[key][idx];
       }
       double total = 0;
       for (int i = 0; i < n; i++) {
           if (((1 << i) & key) != 0) {
               total += places[i].weight;
           } 
       }
       double min = Double.MAX_VALUE;
       for (int i = 0; i < n; i++) {
           if (((1 << i) & key) != 0) {
               double time = (Math.abs(x - places[i].x) + Math.abs(y - places[i].y)) * (total + 100.0) / 120.0 + places[i].weight;
               min = Math.min(min, dfw(key ^ (1 << i), i, places[i].x, places[i].y) + time);
           } 
       }
       dp[key][idx] = min;
       return min;
   }
   
   static class Place {
       int x;
       int y;
       double weight;
       
       public Place(String[] args) {
           x = Integer.parseInt(args[0]);
           y = Integer.parseInt(args[1]);
           weight = Double.parseDouble(args[2]);
       }
   }
}
            
            
            
        