結果

問題 No.1111 コード進行
ユーザー tentententen
提出日時 2020-08-18 07:28:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 2,483 ms
コンパイル使用メモリ 79,568 KB
実行使用メモリ 171,232 KB
最終ジャッジ日時 2024-04-20 01:32:47
合計ジャッジ時間 15,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
41,496 KB
testcase_01 AC 139 ms
41,552 KB
testcase_02 AC 135 ms
41,252 KB
testcase_03 AC 132 ms
41,304 KB
testcase_04 AC 136 ms
41,244 KB
testcase_05 AC 143 ms
42,620 KB
testcase_06 AC 197 ms
44,444 KB
testcase_07 AC 202 ms
44,004 KB
testcase_08 AC 204 ms
43,120 KB
testcase_09 AC 209 ms
43,252 KB
testcase_10 AC 170 ms
48,000 KB
testcase_11 AC 193 ms
42,716 KB
testcase_12 AC 229 ms
47,772 KB
testcase_13 AC 169 ms
43,300 KB
testcase_14 AC 267 ms
48,592 KB
testcase_15 AC 178 ms
42,156 KB
testcase_16 AC 215 ms
47,588 KB
testcase_17 AC 153 ms
47,904 KB
testcase_18 AC 149 ms
42,020 KB
testcase_19 AC 153 ms
41,676 KB
testcase_20 AC 160 ms
42,796 KB
testcase_21 AC 152 ms
41,760 KB
testcase_22 AC 158 ms
47,720 KB
testcase_23 AC 171 ms
43,276 KB
testcase_24 AC 163 ms
43,384 KB
testcase_25 AC 244 ms
47,720 KB
testcase_26 AC 250 ms
48,248 KB
testcase_27 AC 178 ms
42,588 KB
testcase_28 AC 212 ms
101,324 KB
testcase_29 AC 182 ms
67,016 KB
testcase_30 AC 381 ms
82,284 KB
testcase_31 AC 176 ms
47,748 KB
testcase_32 AC 426 ms
77,544 KB
testcase_33 AC 497 ms
68,696 KB
testcase_34 AC 194 ms
79,976 KB
testcase_35 AC 213 ms
100,792 KB
testcase_36 AC 298 ms
98,688 KB
testcase_37 AC 256 ms
56,220 KB
testcase_38 AC 391 ms
58,172 KB
testcase_39 AC 591 ms
81,912 KB
testcase_40 AC 597 ms
101,556 KB
testcase_41 AC 253 ms
120,984 KB
testcase_42 AC 269 ms
66,856 KB
testcase_43 AC 522 ms
73,516 KB
testcase_44 AC 185 ms
56,016 KB
testcase_45 AC 209 ms
77,524 KB
testcase_46 AC 221 ms
43,524 KB
testcase_47 AC 404 ms
171,232 KB
testcase_48 AC 235 ms
46,316 KB
testcase_49 AC 190 ms
43,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static ArrayList<HashMap<Integer, Integer>> list = new ArrayList<>();
    static int[][][] dp;
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		for (int i = 0; i <= 300; i++) {
		    list.add(new HashMap<>());
		}
		for (int i = 0; i < m; i++) {
		    int p = sc.nextInt();
		    int q = sc.nextInt();
		    int c = sc.nextInt();
		    list.get(q).put(p, c);
		}
		dp = new int[n][k + 1][301];
		for (int[][] arr1 : dp) {
		    for (int[] arr2 : arr1) {
		        Arrays.fill(arr2, -1);
		    }
		}
		int ans = 0;
		for (int i = 1; i <= 300; i++) {
		    ans += dfw(n - 1, k, i);
		    ans %= MOD;
		}
		System.out.println(ans);
    }
    
    static int dfw(int idx, int value, int code) {
        if (idx == 0 && value == 0) {
            return 1;
        }
        if (idx <= 0 || value < 0) {
            return 0;
        }
        if (dp[idx][value][code] >= 0) {
            return dp[idx][value][code];
        }
        int ans = 0;
        for (Map.Entry<Integer, Integer> entry : list.get(code).entrySet()) {
            ans += dfw(idx - 1, value - entry.getValue(), entry.getKey());
            ans %= MOD;
        }
        dp[idx][value][code] = ans;
        return ans;
    }
}

0