結果

問題 No.506 限られたジャパリまん
ユーザー 0214sh70214sh7
提出日時 2017-03-25 16:05:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 28,588 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-10 12:50:31
合計ジャッジ時間 1,712 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
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,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);i++)
#define INF 1000000007
int add(int);
bool friends[35]={};//0であげない 1であげる

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];
	scanf("%d %d %d %d",&H,&W,&K,&P);
	REP(i,K){scanf("%d %d %s",&x[i],&y[i],N[i]);}
	while(friends[K]==0){
		REP(i,K){e+=friends[i];}
		if(e>P){goto JUMP;}
		REP(i,H+1){
			REP(j,W+1){
				dp[i][j]= -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||j==0){
						if(dp[i-1][0]!=0 && dp[0][j-1]!=0){
							dp[i][j]=1;
						}else{
							dp[i][j]=0;
						}
					}else{
						dp[i][j] = dp[i-1][j]+dp[i][j-1];
					}
				}

			}
		}
		if(dp[H][W]>max){
			max=dp[H][W];
			REP(i,K){max_friends[i]=friends[i];}
		}
		
		JUMP:
		e=0;
		add(0);
		
	}

	printf("%lld\n",max%INF);
	REP(i,K){if(max_friends[i]==1){printf("%s\n",N[i]);}}
	return 0;
}

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