結果

問題 No.506 限られたジャパリまん
ユーザー myantamyanta
提出日時 2017-06-30 02:14:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 53,980 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:54:45
合計ジャッジ時間 1,660 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using ll=long long;
using vll=vector<ll>;
using vvll=vector<vll>;


struct friend_t
{
	int x, y;
	char name[10+2];
};


int main(void)
{
	int w, h, k, p;

	while(scanf("%d%d%d%d", &w, &h, &k, &p)==4)
	{
		vector<friend_t> f(k);
		vi use(k), ans_use(k);
		vvll dp(h+1);
		ll ans=0;

		for(int i=0;i<k;i++)
		{
			scanf("%d%d%10s", &f[i].x, &f[i].y, f[i].name);
			use[i]=(i<p);
		}

		do
		{
			for(auto&dpe:dp) dpe.assign(w+1, 0);
			dp[0][0]=1;

			for(int i=0;i<k;i++)
			{
				if(!use[i]) dp[f[i].y][f[i].x]=-1;
			}
			for(int y=0;y<=h;y++)
			{
				for(int x=0;x<=w;x++)
				{
					if(dp[y][x]<0) continue;
					if(y>0 && dp[y-1][x  ]>0) dp[y][x]+=dp[y-1][x  ];
					if(x>0 && dp[y  ][x-1]>0) dp[y][x]+=dp[y  ][x-1];
				}
			}
			if(ans<dp[h][w])
			{
				ans=dp[h][w];
				ans_use=use;
			}
		}
		while(prev_permutation(use.begin(), use.end()));

		printf("%d\n", (int)(ans%1000000007));
		for(int i=0;i<k;i++)
		{
			if(ans_use[i]) printf("%s\n", f[i].name);
		}
	}

	return 0;
}
0