結果

問題 No.506 限られたジャパリまん
ユーザー tkmst201tkmst201
提出日時 2017-04-23 13:23:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,321 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 147,204 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:53:51
合計ジャッジ時間 2,788 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int H, W, K, P;
int x[15], y[15];
string name[15];

bool done[33][33];
ll dp[33][33];

int main() {
	cin >> W >> H >> K >> P;
	REP(i, K) cin >> x[i] >> y[i] >> name[i];
	
	pll ans = pll(-1, 0); // 数, 集合
	
	REP(s, 1<<K) {
		int cnt = 0;
		REP(i, K) if (s >> i & 1) cnt++;
		if (cnt > P) continue;
		
		memset(done, 0, sizeof(done));
		REP(i, K) if (!(s >> i & 1)) done[y[i]][x[i]] = true;
		
		memset(dp, 0, sizeof(dp));
		
		dp[0][0] = !done[0][0];
		
		REP(i, H + 1) REP(j, W + 1) {
			if (done[i][j]) continue;
			
			if (i > 0) dp[i][j] += dp[i - 1][j];
			if (j > 0) dp[i][j] += dp[i][j - 1];
		}
		
		chmax(ans, pll(dp[H][W], s));
	}
	
	printf("%lld\n", ans.first % MOD);
	REP(i, K) if (ans.second >> i & 1) printf("%s\n", name[i].c_str());
	
	return 0;
}
0