結果

問題 No.506 限られたジャパリまん
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-04 20:22:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,598 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 166,244 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:56:37
合計ジャッジ時間 2,594 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 17 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 15 ms
4,380 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.04 20:22:23
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

constexpr int MOD = 1e9 + 7;
int bitpopcount(ll n) {
    int res = 0;
    while (n) {
        if (n & 1) res++;
        n >>= 1;
    }
    return res;
}
int main() {
    int h,w,k,p;
    cin >> h >> w >> k >> p;
    vector<tuple<int,int,string>> a(k);
    for (int i = 0; i < k; i++) {
        int x,y;string s;cin >> x >> y >> s;
        a[i] = make_tuple(x,y,s);
    }
    ll ans = 0;
    vector<string> ans_vec;
    for (int i = 0; i < (1<<k); i++) {
        if (bitpopcount(i) != p) continue;
        vector<vector<bool>> ok(h + 1,vector<bool>(w + 1,true));
        for (int j = 0; j < k; j++) {
            if (!(i & (1 << j))) ok[get<0>(a[j])][get<1>(a[j])] = false;
        }
        vector<vector<ll>> dp(h + 1,vector<ll>(w + 1,0));
        dp[0][0] = 1;
        for (int x = 0; x <= h; x++) {
            for (int y = 0; y <= w; y++) {
                if (!ok[x][y]) continue;
                if (x >= 1) dp[x][y] += dp[x-1][y];
                if (y >= 1) dp[x][y] += dp[x][y-1];
            }
        }
        if (ans < dp[h][w]) {
            ans = dp[h][w];
            vector<string> vec;
            for (int j = 0; j < k; j++) {
                if (i & (1 << j)) {
                    vec.push_back(get<2>(a[j]));
                }
            }
            ans_vec = vec;
        }
    }
    cout << ans % MOD << endl;
    for (int i = 0; i < ans_vec.size(); i++) {
        cout << ans_vec[i] << endl;
    }
    return 0;
}
0