結果

問題 No.506 限られたジャパリまん
ユーザー fiord
提出日時 2017-07-12 07:48:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 998 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,408 KB
最終ジャッジ日時 2024-06-28 04:19:48
合計ジャッジ時間 7,968 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w, k, p = map(int, input().split())
dat = []
for i in range(k):
    x, y, n = input().split()
    x = int(x)
    y = int(y)
    dat.append([x, y, n])
ret = 0
num = 0
for i in range(1 << k):
    if p < bin(i).count("1"):
        continue
    cnt = [[0] * (w + 1) for j in range(h + 1)]
    cnt[0][0] = 1
    for j in range(k):
        if not (i >> j) & 1:
            cnt[dat[j][0]][dat[j][1]] = -1
    for x in range(h + 1):
        for y in range(w + 1):
            if cnt[x][y] == -1:
                continue
            if x + 1 <= h and cnt[x + 1][y] != -1:
                cnt[x + 1][y] += cnt[x][y]
            if y + 1 <= w and cnt[x][y + 1] != -1:
                cnt[x][y + 1] += cnt[x][y]
    if cnt[h][w] > num:
        num = cnt[h][w]
        ret = i
print(num % (10**9 + 7))
for i in range(k):
    if (ret >> i) & 1:
        print(dat[i][2])
0