結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-26 15:16:44 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 12 ms / 2,000 ms | 
| コード長 | 1,537 bytes | 
| コンパイル時間 | 1,882 ms | 
| コンパイル使用メモリ | 185,844 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:23:40 | 
| 合計ジャッジ時間 | 2,721 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const  int MOD = 1000000007;
struct animal{
    int x,y;
    string name;
};
int main(){
    int h,w,k,p;
    cin >> h >> w >> k >> p;
    vector<animal> friends(k);
    rep(i,k) cin >> friends[i].x >> friends[i].y >> friends[i].name;
    vector<vector<bool>> maze(h+1,vector<bool>(w+1,false));
    rep(i,k) maze[friends[i].x][friends[i].y] = true;
    vector<string> ans;
    ll mx = 0;
    rep(bit,1<<k){
        int s = __builtin_popcount(bit);
        vector<int> res;
        if(s != p) continue;
        rep(i,k){
            if(bit>>i &1){
                maze[friends[i].x][friends[i].y] = false;
                res.push_back(i);
            }
        }
        vector<vector<ll>> dp(h+1,vector<ll>(w+1,0));
        dp[0][0] = 1;
        rep(i,h+1)rep(j,w+1){
            if(maze[i][j]){
                dp[i][j] = 0;
                continue;
            }
            if(i>0) dp[i][j] += dp[i-1][j];
            if(j>0) dp[i][j] += dp[i][j-1];
        }
        for(int i:res){
            maze[friends[i].x][friends[i].y] = true;
        }
        if(dp[h][w] > mx){
            mx = dp[h][w];
            vector<string> empty;
            swap(empty,ans);
            for(int i:res){
                ans.push_back(friends[i].name);
            }
        }
    }
    cout << mx%MOD << endl;
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}
            
            
            
        