結果
| 問題 |
No.506 限られたジャパリまん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-21 16:59:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,903 bytes |
| コンパイル時間 | 1,040 ms |
| コンパイル使用メモリ | 87,996 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-28 04:21:43 |
| 合計ジャッジ時間 | 1,949 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 14 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct friends{
int y, x;
string name;
};
int H, W, K, P;
vector<vector<bool>> space;
vector<vector<long>> dp;
long move(int now_y, int now_x){
if(dp[now_y][now_x] != -1){
return dp[now_y][now_x];
}else if(now_y == H && now_x == W){
return dp[now_y][now_x] = 1;
}else if(now_y == H){
return dp[now_y][now_x] = move(now_y, now_x + 1) * space[now_y][now_x + 1];
}else if(now_x == W){
return dp[now_y][now_x] = move(now_y + 1, now_x) * space[now_y + 1][now_x];
}else{
return dp[now_y][now_x] = move(now_y, now_x + 1) * space[now_y][now_x + 1] + move(now_y + 1, now_x) * space[now_y + 1][now_x];
}
}
int main(){
cin >> H >> W >> K >> P;
space.resize(H + 1, vector<bool>(W + 1, true));
friends friendss[K];
for(int i = 0; i < K; i++){
cin >> friendss[i].y >> friendss[i].x >> friendss[i].name;
}
long ans = -1;
int ans_number = -1;
dp.resize(H + 1, vector<long>(W + 1));
for(int i = 0; i < (1 << K); i++){
if(__builtin_popcount(i) == P){
for(int j = 0; j < K; j++){
if(~(i >> j) & 1){
space[friendss[j].y][friendss[j].x] = false;
}
}
for(int j = 0; j <= H; j++){
for(int k = 0; k <= W; k++){
dp[j][k] = -1;
}
}
long this_ans = move(0, 0);
if(this_ans > ans){
ans = this_ans;
ans_number = i;
}
for(int j = 0; j < K; j++){
space[friendss[j].y][friendss[j].x] = true;
}
}
}
cout << ans << endl;
for(int i = 0; i < K; i++){
if((ans_number >> i) & 1){
cout << friendss[i].name << endl;
}
}
}