結果

問題 No.506 限られたジャパリまん
ユーザー fiord
提出日時 2017-07-12 07:47:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 859 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 16,128 KB
最終ジャッジ日時 2024-06-28 04:19:29
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

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