結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  maspy | 
| 提出日時 | 2020-03-17 22:53:40 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 112 ms / 2,000 ms | 
| コード長 | 1,179 bytes | 
| コンパイル時間 | 402 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 76,544 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:23:16 | 
| 合計ジャッジ時間 | 2,609 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
MOD = 10**9 + 7
# %%
H, W, K, P = map(int, readline().split())
X = []
Y = []
N = []
for _ in range(K):
    x, y, n = readline().decode().split()
    x = int(x)
    y = int(y)
    X.append(x)
    Y.append(y)
    N.append(n)
# %%
def solve(subset):
    dp = [[0] * (W + 2) for _ in range(H + 2)]
    dp[0][0] = 1
    forbit = [[0] * (W + 1) for _ in range(H + 1)]
    for i in subset:
        x = X[i]
        y = Y[i]
        forbit[x][y] = 1
    for h in range(H + 1):
        for w in range(W + 1):
            if forbit[h][w]:
                dp[h][w] = 0
                continue
            dp[h + 1][w] += dp[h][w]
            dp[h][w + 1] += dp[h][w]
    return dp[H][W]
# %%
best_subset = 0
best_path = 0
for s in itertools.combinations(range(K), K - P):
    x = solve(s)
    if best_path < x:
        best_path = x
        best_subset = s
# %%
if best_path == 0:
    print(0)
else:
    print(best_path % MOD)
    for i in range(K):
        if i in best_subset:
            continue
        print(N[i])
            
            
            
        