結果

問題 No.2711 Connecting Lights
ユーザー tentententen
提出日時 2024-05-07 17:22:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 319 ms / 5,000 ms
コード長 2,082 bytes
コンパイル時間 3,222 ms
コンパイル使用メモリ 79,200 KB
実行使用メモリ 44,784 KB
最終ジャッジ日時 2024-05-07 17:22:54
合計ジャッジ時間 7,333 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
37,368 KB
testcase_01 AC 47 ms
37,108 KB
testcase_02 AC 49 ms
37,108 KB
testcase_03 AC 48 ms
37,360 KB
testcase_04 AC 46 ms
37,236 KB
testcase_05 AC 75 ms
39,604 KB
testcase_06 AC 51 ms
37,368 KB
testcase_07 AC 48 ms
37,544 KB
testcase_08 AC 61 ms
37,848 KB
testcase_09 AC 226 ms
42,364 KB
testcase_10 AC 82 ms
40,884 KB
testcase_11 AC 141 ms
43,892 KB
testcase_12 AC 127 ms
42,152 KB
testcase_13 AC 113 ms
42,972 KB
testcase_14 AC 55 ms
37,716 KB
testcase_15 AC 104 ms
41,084 KB
testcase_16 AC 75 ms
39,636 KB
testcase_17 AC 76 ms
40,152 KB
testcase_18 AC 78 ms
39,924 KB
testcase_19 AC 92 ms
41,768 KB
testcase_20 AC 116 ms
43,392 KB
testcase_21 AC 74 ms
40,064 KB
testcase_22 AC 51 ms
37,632 KB
testcase_23 AC 58 ms
40,104 KB
testcase_24 AC 155 ms
40,660 KB
testcase_25 AC 191 ms
40,916 KB
testcase_26 AC 319 ms
44,784 KB
testcase_27 AC 297 ms
44,636 KB
testcase_28 AC 318 ms
44,736 KB
testcase_29 AC 126 ms
43,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 998244353;
    static int n;
    static int k;
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        n = sc.nextInt();
        int m = sc.nextInt();
        k = sc.nextInt();
        if (m == 1) {
            System.out.println(1 << n);
            return;
        }
        dp = new int[m][1 << n];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(m - 1, (1 << n) - 1));
    }
    
    static int dfw(int idx, int v) {
        if (idx < 0) {
            return 1;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = 0;
            for (int i = 1; i < (1 << n); i++) {
                if (getPop(v & i) >= k) {
                    dp[idx][v] += dfw(idx - 1, i);
                    dp[idx][v] %= MOD;
                }
            }
        }
        return dp[idx][v];
    }
    
    static int getPop(int x) {
        int pop = 0;
        while (x > 0) {
            pop += x % 2;
            x >>= 1;
        }
        return pop;
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0