結果
問題 |
No.506 限られたジャパリまん
|
ユーザー |
![]() |
提出日時 | 2017-04-22 15:54:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 958 bytes |
コンパイル時間 | 1,506 ms |
コンパイル使用メモリ | 169,252 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-28 04:15:57 |
合計ジャッジ時間 | 7,155 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 1 RE * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int mod = 1e9 + 7; int H, W, K, P; int A[33][33]; string Q[15]; int64 dp[33][33]; int64 rec(int y, int x, int bit) { if(y > H || x > W) return (0LL); if(~A[y][x] && (~bit >> A[y][x]) & 1) return (0LL); if(y == H && x == W) return (1LL); if(~dp[y][x]) return (dp[y][x]); return (dp[y][x] = rec(y + 1, x, bit) + rec(y, x + 1, bit)); } int main() { memset(A, -1, sizeof(A)); cin >> H >> W >> K >> P; for(int i = 0; i < K; i++) { int y, x; cin >> y >> x >> Q[i]; A[y][x] = i; } int64 latte = rec(0, 0, 0), malta = 0; for(int i = 1; i < 1 << K; i++) { if(__builtin_popcount(i) > P) continue; memset(dp, -1, sizeof(dp)); auto pp = rec(0, 0, i); if(pp > latte) { latte = pp; malta = i; } } cout << latte % mod << endl; for(int i = 0; i < 1 << K; i++) { if((malta >> i) & 1) cout << Q[i] << endl; } }