結果

問題 No.506 限られたジャパリまん
ユーザー ei1333333ei1333333
提出日時 2017-04-22 15:58:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 165,448 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:53:43
合計ジャッジ時間 4,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 389 ms
4,380 KB
testcase_05 AC 387 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 65 ms
4,376 KB
testcase_09 AC 18 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 176 ms
4,376 KB
testcase_12 AC 74 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 45 ms
4,380 KB
testcase_17 AC 30 ms
4,380 KB
testcase_18 AC 91 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 188 ms
4,380 KB
testcase_21 AC 190 ms
4,376 KB
testcase_22 AC 361 ms
4,376 KB
testcase_23 AC 92 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  }

}
0