結果
| 問題 |
No.506 限られたジャパリまん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-03 20:08:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 1,151 bytes |
| コンパイル時間 | 1,716 ms |
| コンパイル使用メモリ | 177,700 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 04:29:58 |
| 合計ジャッジ時間 | 2,625 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int h, w, k, p, ans = 0;
cin >> h >> w >> k >> p;
vector<string> name(k);
vector<vector<int>> S(h + 1, vector<int>(w + 1));
ll mx = 0;
for(int i = 0; i < k; i++){
int y, x;
cin >> y >> x >> name[i];
S[y][x] = 1 << i;
}
for(int comb = (1 << p) - 1; comb < (1 << k); ){
vector<vector<ll>> dp(h + 1, vector<ll>(w + 1));
dp[0][0] = 1;
for(int y = 0; y <= h; y++){
for(int x = 0; x <= w; x++){
if((S[y][x] & comb) != S[y][x]) continue;
if(y + 1 <= h) dp[y + 1][x] += dp[y][x];
if(x + 1 <= w) dp[y][x + 1] += dp[y][x];
}
}
if(dp[h][w] > mx){
mx = dp[h][w];
ans = comb;
}
if(p == 0) break;
int x = comb & (-comb), y = comb + x;
comb = ((comb & ~y) / x >> 1) | y;
}
cout << mx % 1000000007 << '\n';
while(ans){
cout << name[__lg(ans & -ans)] << '\n';
ans -= ans & -ans;
}
}