結果

問題 No.506 限られたジャパリまん
ユーザー ei1333333ei1333333
提出日時 2017-04-22 15:57:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 1,564 ms
コンパイル使用メモリ 166,772 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:53:39
合計ジャッジ時間 4,804 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 420 ms
4,376 KB
testcase_05 AC 421 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 68 ms
4,376 KB
testcase_09 AC 18 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 189 ms
4,380 KB
testcase_12 AC 79 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 48 ms
4,376 KB
testcase_17 AC 32 ms
4,376 KB
testcase_18 AC 99 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 205 ms
4,380 KB
testcase_21 AC 206 ms
4,376 KB
testcase_22 AC 391 ms
4,376 KB
testcase_23 AC 100 ms
4,380 KB
testcase_24 AC 2 ms
4,380 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[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 < K; i++) {
    if((malta >> i) & 1) cout << Q[i] << endl;
  }

}
0