結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-08-03 07:48:08 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 259 ms / 2,000 ms | 
| コード長 | 2,394 bytes | 
| コンパイル時間 | 1,889 ms | 
| コンパイル使用メモリ | 181,244 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:20:16 | 
| 合計ジャッジ時間 | 4,415 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}
constexpr ll MOD = 1e9 + 7;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;
struct Friend {
    int x;
    int y;
    string name;
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K, P;
    cin >> H >> W >> K >> P;
    vector<Friend> f(K);
    for (ll i = 0; i < K; i++) {
        cin >> f[i].x >> f[i].y >> f[i].name;
    }
    const int maximum = 1LL << K;
    ll maxi = 0;
    ll maxf = -1;
    for (ll i = 0; i < maximum; i++) {
        vector<vector<bool>> ok(H + 1, vector<bool>(W + 1, true));
        vector<vector<ll>> dp(H + 1, vector<ll>(W + 1, 0));
        ll num = i;
        int cnt = 0;
        for (int j = 0; j < K; j++) {
            if (num % 2 == 1) {
                ok[f[j].x][f[j].y] = false;
                dp[f[j].x][f[j].y] = 0;
            } else {
                cnt++;
            }
            num /= 2;
        }
        if (cnt > P) {
            continue;
        }
        for (int x = 0; x <= H; x++) {
            if (ok[x][0]) {
                dp[x][0] = 1;
            } else {
                break;
            }
        }
        for (int y = 0; y <= W; y++) {
            if (ok[0][y]) {
                dp[0][y] = 1;
            } else {
                break;
            }
        }
        for (int x = 1; x <= H; x++) {
            for (int y = 1; y <= W; y++) {
                if (ok[x][y]) {
                    dp[x][y] = (dp[x - 1][y] + dp[x][y - 1]);
                }
            }
        }
        if (maxi < dp[H][W]) {
            maxi = dp[H][W];
            maxf = i;
        }
    }
    cout << maxi % MOD << endl;
    if (maxi > 0) {
        for (int i = 0; i < K; i++) {
            if (maxf % 2 == 0) {
                cout << f[i].name << endl;
            }
            maxf /= 2;
        }
    }
    return 0;
}
            
            
            
        