結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  🍮かんプリン | 
| 提出日時 | 2020-06-04 20:22:30 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 17 ms / 2,000 ms | 
| コード長 | 1,598 bytes | 
| コンパイル時間 | 1,669 ms | 
| コンパイル使用メモリ | 180,164 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:24:24 | 
| 合計ジャッジ時間 | 2,599 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
/**
 *   @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;
}
            
            
            
        