結果

問題 No.506 限られたジャパリまん
ユーザー 0214sh70214sh7
提出日時 2017-04-20 01:44:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 67,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:50:40
合計ジャッジ時間 2,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <assert.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
int add(int);
bool friends[35]={};

int main(){
	int H,W,K,P;
	int x[35],y[35];
	char N[21][12];
	long long int dp[35][35]={};
	long long int max=0;
	int e=0;
	bool max_friends[35]={};
	cin >> H >> W >> K >> P;
	assert(1<=K&&K<=15);
	REP(i,K){cin>>x[i]>>y[i]>>N[i];}
	while(friends[K]==0){
		REP(i,K){e+=friends[i];}
		if(e<=P){
	    	REP(i,H+1){
	    		REP(j,W+1){
	    			dp[i][j]= -1;
	    		}
	    	}
	    	dp[0][0]=1;
	    	REP(i,K){if(friends[i]==0){dp[x[i]][y[i]] = 0;}}
	    	REP(i,H+1){
			    REP(j,W+1){
			    	if(dp[i][j]==-1){
			    	    if(i==0 && dp[0][j-1]!=0){
			    	        dp[i][j]=1;
			    	    }else if(j==0 && dp[i-1][0]!=0){
			    	        dp[i][j]=1;
			    	    }else if(i!=0 && j!=0){
			    	        dp[i][j] = dp[i-1][j]+dp[i][j-1];
			    	    }else{
			    	        dp[i][j]=0;
			    	    }
			    		
				    }   

	    		}
	    	}
	    	//REP(i,H+1){REP(j,W+1){cout<<dp[i][j]<<" ";}cout<<endl;}
	    	if(dp[H][W]>max){
	    		max=dp[H][W];
	    		REP(i,K){max_friends[i]=friends[i];}
	    		//cout << max << endl;
	    	}
    
		}
		e=0;
		add(0);

	}

	cout << max % MOD <<endl;
	REP(i,K){if(max_friends[i]==1){cout<<N[i]<<endl;}}
	return 0;
}

int add(int a){
	if(friends[a]==0){
		friends[a]=1;
	}else{
		friends[a]=0;
		add(a+1);
	}
	return 0;
}
0