結果
問題 | No.506 限られたジャパリまん |
ユーザー |
|
提出日時 | 2022-09-13 06:18:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 1,269 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 77,440 KB |
最終ジャッジ日時 | 2024-06-28 04:28:45 |
合計ジャッジ時間 | 3,138 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
from collections import * from itertools import * from functools import * import math,sys H,W,K,P = map(int,input().split()) XYZ = [tuple(input().split()) for _ in range(K)] H += 1 W += 1 XY = [tuple(map(int,(x,y))) for x,y,z in XYZ] def answer(S): dp = [[0]*W for _ in range(H)] dp[0][0]=1 for i in range(H-1): if S[i+1][0]==-1: continue dp[i+1][0]+=dp[i][0] for j in range(W-1): if S[0][j+1]==-1: continue dp[0][j+1]+=dp[0][j] for i in range(H-1): for j in range(W-1): if S[i+1][j+1]==-1: continue dp[i+1][j+1] += dp[i][j+1]+dp[i+1][j] return dp[-1][-1] def bitcnt(x): return bin(x).count('1') mod = 10**9 + 7 ans = 0 X = [] for i in range(2**K): if bitcnt(i)!=K-P: continue cnd = [] for j in range(K): if (i>>j)&1: cnd.append(j) S = [[0]*W for _ in range(H)] for j in cnd: x,y = XY[j] S[x][y]=-1 tmp = answer(S) if tmp>ans: ans = tmp X = tuple(cnd) print(ans%mod) if ans==0: exit() for i in range(K): if i in X: continue print(XYZ[i][2])