結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-04-22 13:39:07 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 11 ms / 2,000 ms | 
| コード長 | 1,809 bytes | 
| コンパイル時間 | 814 ms | 
| コンパイル使用メモリ | 80,408 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:15:48 | 
| 合計ジャッジ時間 | 1,613 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <climits>
using namespace std;
const long long inf = 9e18;
const int mod = 1e9 + 7;
int h, w, k, p;
vector<int> x, y;
void check() {
	w = 32;
	h = 32;
	vector<vector<long long>> board(h+1, vector<long long>(w+1, 0));
	for (int i = 0; i <= h; i++) {
		board[i][0] = 1;
	}
	for (int i = 0; i <= w; i++) {
		board[0][1] = 1;
	}
	for (int i = 1; i <= h; i++) {
	for (int j = 1; j <= w; j++) {
		board[i][j] += board[i-1][j] + board[i][j - 1];
		printf("%2d %2d: %20llu\n", i, j, board[i][j]);
	}}
}
long long calc(int ok_bits) {
	// 東西方向にHメートル、南北方向にWメートル
	vector<vector<long long>> board(w+2, vector<long long>(h+2, 0));
	board[0][0] = 1;
	// vector<string> aaa(w+1, string(h+1, '.'));
	for (int i = 0; i < k; i++) {
		if ((ok_bits >> i) & 1) {
			continue;
		}
		board[y[i]][x[i]] = -inf;
		// aaa[y[i]][x[i]] = 'x';
	}
	for (int i = 0; i <= w; i++) {
	for (int j = 0; j <= h; j++) {
		if (board[i][j] > 0) {
			board[i+1][j] += board[i][j];
			board[i][j+1] += board[i][j];
		}
	}}
	// for (auto s : aaa) {
	// 	cout << s << endl;
	// }
	return max(board[w][h], 0LL);
}
int main() {
	cin >> h >> w >> k >> p;
	x.assign(k, 0);
	y.assign(k, 0);
	vector<string> name(k);
	for (int i = 0; i < k; i++) {
		cin >> x[i] >> y[i] >> name[i];
	}
	long long ans = 0;
	int store = 0;
	for (int i = 0; i < (1 << k); i++) {
		if (__builtin_popcount(i) != p) {
			continue;
		}
		auto val = calc(i);
// printf("%5d: %20lld, %20lld\n", i, val, val % mod);
		if (val > ans) {
			ans = val;
			store = i;
		}
	}
	ans %= mod;
	cout << ans << endl;
	for (int i = 0; i < k; i++) {
		if ((store >> i) & 1) {
			cout << name[i] << endl;
		}
	}
	return 0;
}
            
            
            
        