結果
問題 | No.2711 Connecting Lights |
ユーザー |
![]() |
提出日時 | 2024-05-07 17:22:45 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,015 ms / 5,000 ms |
コード長 | 2,082 bytes |
コンパイル時間 | 4,180 ms |
コンパイル使用メモリ | 78,880 KB |
実行使用メモリ | 44,768 KB |
最終ジャッジ日時 | 2024-11-30 12:02:03 |
合計ジャッジ時間 | 8,312 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
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(); } } }