結果

問題 No.66 輝け☆全国たこやき杯
ユーザー fujisufujisu
提出日時 2015-05-12 04:28:58
言語 Java19
(openjdk 21)
結果
AC  
実行時間 212 ms / 5,000 ms
コード長 3,082 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 74,944 KB
実行使用メモリ 65,372 KB
最終ジャッジ日時 2023-09-20 03:27:37
合計ジャッジ時間 5,259 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,216 KB
testcase_01 AC 115 ms
55,700 KB
testcase_02 AC 115 ms
55,824 KB
testcase_03 AC 115 ms
55,940 KB
testcase_04 AC 119 ms
55,956 KB
testcase_05 AC 128 ms
55,424 KB
testcase_06 AC 128 ms
55,768 KB
testcase_07 AC 163 ms
56,212 KB
testcase_08 AC 183 ms
58,348 KB
testcase_09 AC 212 ms
65,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	double[][] dp;
	double[][] p;

	double dp(int q, int k, int low, int high) {
		if (0 <= dp[q][k]) {
			return dp[q][k];
		}
		if (q == 0) {
			return 1.;
		}

		double res = 0;
		int mid = (low + high) / 2;
		for (int i = low; i < high; i++) {
			if (k < mid == i < mid) {
				continue;
			}
			if (k < mid) {
				res += dp(q - 1, k, low, mid) * dp(q - 1, i, mid, high) * p[k][i];
			} else {
				res += dp(q - 1, i, low, mid) * dp(q - 1, k, mid, high) * p[k][i];
			}
		}
		return dp[q][k] = res;
	}

	void run() {
		MyScanner sc = new MyScanner();

		int n = sc.nextInt();
		double[] a = new double[1 << n];
		for (int i = 0; i < 1 << n; i++) {
			a[i] = sc.nextInt();
		}
		p = new double[1 << n][1 << n];
		for (int i = 0; i < 1 << n; i++) {
			for (int j = 0; j < 1 << n; j++) {
				p[i][j] = (a[i] * a[i]) / (a[i] * a[i] + a[j] * a[j]);
			}
		}

		dp = new double[n + 1][1 << n];
		for (int i = 0; i < n + 1; i++) {
			Arrays.fill(dp[i], -1);
		}

		System.out.printf("%.7f\n", dp(n, 0, 0, 1 << n));
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}
0