結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  ei1333333 | 
| 提出日時 | 2017-04-22 15:58:33 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 357 ms / 2,000 ms | 
| コード長 | 944 bytes | 
| コンパイル時間 | 1,522 ms | 
| コンパイル使用メモリ | 167,520 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:16:30 | 
| 合計ジャッジ時間 | 4,222 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int mod = 1e9 + 7;
int H, W, K, P;
int A[50][50];
string Q[50];
int64 dp[50][50];
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 = -1, malta = -1;
  for(int i = 0; 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 < K; i++) {
    if((malta >> i) & 1) cout << Q[i] << endl;
  }
}
            
            
            
        