結果

問題 No.506 限られたジャパリまん
ユーザー finefine
提出日時 2017-04-22 16:24:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,057 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 167,336 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:53:39
合計ジャッジ時間 2,544 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int x[15], y[15];
string N[15];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, K, P;
	cin >> H >> W >> K >> P;
	for (int i = 0; i < K; i++) {
		cin >> x[i] >> y[i] >> N[i];
	}

	int ansf = 0;
	ll ansc = 0;

	for (int i = 0; i < (1 << K); i++) {
		if (__builtin_popcount(i) != P) continue;
		int f[33][33] = {};
		for (int j = 0; j < K; j++) {
			if (i & (1 << j)) continue;
			f[x[j]][y[j]] = 1;
		}
		if (f[0][0]) continue;
		ll dp[33][33] = {};
		dp[0][0] = 1;
		for (int j = 1; j <= H; j++) {
			if (!f[j][0]) dp[j][0] += dp[j - 1][0];
		}
		for (int j = 1; j <= W; j++) {
			if (!f[0][j]) dp[0][j] += dp[0][j - 1];
		}
		for (int j = 1; j <= H; j++) {
			for (int k = 1; k <= W; k++) {
				if (!f[j][k]) dp[j][k] = dp[j - 1][k] + dp[j][k - 1];
			}
		}
		if (ansc < dp[H][W]) {
			ansc = dp[H][W];
			ansf = i;
		}
	}

	cout << ansc << endl;
	for (int i = 0; i < K; i++) {
		if (ansf & (1 << i)) cout << N[i] << endl;
	}
	return 0;
}
0