結果
問題 |
No.506 限られたジャパリまん
|
ユーザー |
![]() |
提出日時 | 2017-04-28 19:27:12 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 353 ms / 2,000 ms |
コード長 | 2,737 bytes |
コンパイル時間 | 933 ms |
コンパイル使用メモリ | 110,476 KB |
実行使用メモリ | 26,752 KB |
最終ジャッジ日時 | 2024-06-28 04:17:25 |
合計ジャッジ時間 | 3,910 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; public class Program { public static void Main(string[] args) { new Magatro().Solve(); } } class Magatro { private int H, W, K, P; private int[] x, y; private string[] N; private void Scan() { string[] line = Console.ReadLine().Split(' '); H = int.Parse(line[0]); W = int.Parse(line[1]); K = int.Parse(line[2]); P = int.Parse(line[3]); x = new int[K]; y = new int[K]; N = new string[K]; for (int i = 0; i < K; i++) { line = Console.ReadLine().Split(' '); x[i] = int.Parse(line[0]); y[i] = int.Parse(line[1]); N[i] = line[2]; } } public void Solve() { Scan(); long max = 0; int ans = 0; for (int i = 0; i < (1 << K); i++) { if (BitCount(i) != P) { continue; } long cnt = Count(i); if (max < cnt) { ans = i; max = cnt; } } Console.WriteLine(max%((int)1e9+7)); for (int i = 0; i < K; i++) { int j = 1 << i; if ((ans & j) != 0) { Console.WriteLine(N[i]); } } } private long Count(int i) { var d = new Dictionary<Pair<int, int>, bool>(); for (int j = 0; j < K; j++) { int k = 1 << j; if ((i & k) == 0) { d[new Pair<int, int>(x[j], y[j])] = true; } } var dp = new long[H + 1, W + 1]; dp[0, 0] = 1; for (int j = 0; j <= H; j++) { for (int k = 0; k <= W; k++) { bool o; if (d.TryGetValue(new Pair<int, int>(j, k), out o)) continue; if (j < H) { dp[j + 1, k] += dp[j, k]; } if (k < W) { dp[j, k + 1] += dp[j, k]; } } } return dp[H, W]; } private int BitCount(int n) { int cnt = 0; for (int i = 0; i < K; i++) { if (n % 2 == 1) { cnt++; } n /= 2; } return cnt; } } struct Pair<F, S> { public F First; public S Second; public Pair(F f, S s) { First = f; Second = s; } }