結果
| 問題 |
No.506 限られたジャパリまん
|
| コンテスト | |
| ユーザー |
hiyokko2
|
| 提出日時 | 2017-08-03 19:20:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,310 bytes |
| コンパイル時間 | 1,434 ms |
| コンパイル使用メモリ | 163,324 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 04:20:05 |
| 合計ジャッジ時間 | 2,277 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;
int H, W, K, P;
int x[20], y[20];
string N[20];
int dp[40][40];
bool can_move[40][40]; //通れないところはfalse
signed main()
{
cin >> H >> W >> K >> P;
REP(i,K) cin >> x[i] >> y[i] >> N[i];
int ma = 0;
vector<string> ans;
for (int i=0; i<(1<<K); i++) {
//ビットが立っているところは通れない
if (__builtin_popcount(i) != K - P) continue;
REP(j,40) REP(k,40) can_move[j][k] = true;
REP(j,K) if (i >> j & 1) can_move[x[j]][y[j]] = false;
for (int x=0; x<=H; x++) {
for (int y=0; y<=W; y++) {
dp[x][y] = (x == 0 && y == 0 ? 1 : 0);
if (0 <= x - 1) dp[x][y] += dp[x-1][y];
if (0 <= y - 1) dp[x][y] += dp[x][y-1];
if (!can_move[x][y]) dp[x][y] = 0;
}
}
if (ma < dp[H][W]) {
ma = dp[H][W];
ans.clear();
REP(j,K) if (~i >> j & 1) ans.push_back(N[j]);
}
}
cout << ma % MOD << endl;
REP(i,ans.size()) cout << ans[i] << endl;
}
hiyokko2