結果

問題 No.520 プロジェクトオイラーへの招待
ユーザー 37zigen37zigen
提出日時 2017-05-29 00:35:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,591 bytes
コンパイル時間 4,383 ms
コンパイル使用メモリ 77,592 KB
実行使用メモリ 73,508 KB
最終ジャッジ日時 2023-10-21 14:51:06
合計ジャッジ時間 5,634 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
66,280 KB
testcase_01 AC 162 ms
66,280 KB
testcase_02 AC 161 ms
66,260 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 170 ms
66,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

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

	long MODULO = 1_000_000_000 + 7;
	long[][] comb = new long[300][300];

	void run() {
		comb[0][0] = 1;
		for (int i = 1; i < comb.length; ++i) {
			for (int j = 0; j <= i; ++j) {
				comb[i][j] = (comb[i - 1][j] + (j > 0 ? comb[i - 1][j - 1] : 0)) % MODULO;
			}
		}
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < rec.length; ++i) {
			for (int j = 0; j < rec[i].length; ++j) {
				for (int k = 0; k < rec[i][j].length; ++k) {
					rec[i][j][k] = -1;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			System.out.println(f(a, b, c));
		}
	}

	long[][][] rec = new long[101][101][101];

	long f(int a, int b, int c) {
		if (a < 0 || b < 0 || c < 0) {
			return 0;
		}
		if (a == 0 && b == 0 && c == 0) {
			return 1;
		}
		if (rec[a][b][c] != -1) {
			return rec[a][b][c];
		}
		int all = a + b + c - 1;
		long ret = ((a > 0 ? comb[all][a - 1] : 0) + (b > 0 ? comb[all][b - 1] : 0) + (c > 0 ? comb[all][c - 1] : 0))
				% MODULO;
		if (a > 0 && b > 0 && c > 0) {
			for (int i = 0; i < a; ++i) {
				for (int j = 0; j < b; ++j) {
					for (int k = 0; k < c; ++k) {
						ret += f(i, (c - 1) - k, 0) * f((a - 1) - i, j, 0) * f((b - 1) - j, k, 0);
					}
				}
			}
		}
		ret %= MODULO;
		rec[a][b][c] = ret;
		return ret;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0