結果
| 問題 | No.506 限られたジャパリまん | 
| コンテスト | |
| ユーザー |  myanta | 
| 提出日時 | 2017-06-30 02:14:26 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 2,000 ms | 
| コード長 | 1,109 bytes | 
| コンパイル時間 | 555 ms | 
| コンパイル使用メモリ | 50,688 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-28 04:18:58 | 
| 合計ジャッジ時間 | 1,386 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |                         scanf("%d%d%10s", &f[i].x, &f[i].y, f[i].name);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#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;
}
            
            
            
        