結果

問題 No.37 遊園地のアトラクション
ユーザー myantamyanta
提出日時 2017-05-04 18:15:15
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,141 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 47,616 KB
実行使用メモリ 7,928 KB
最終ジャッジ日時 2023-10-12 08:02:58
合計ジャッジ時間 8,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<vector>


using namespace std;


struct a_t
{
	int c, v;
};


vector<a_t> a;
vector<vector<int> > memo;


int max(int a, int b)
{
	if(a>b) return a;
	return b;
}


int max_u(int& m, int v)
{
	if(m<v)
	{
		m=v;
		return 1;
	}
	return 0;
}


int solve_r(int t, int v, int n)
{
	int ret;

//	if(memo[n][t]>=0) return memo[n][t];

	if(n<=0)
	{
		return memo[n][t]=v;
	}
	ret=solve_r(t, v, n-1);
	if(t>=a[n-1].c) max_u(ret, solve_r(t-a[n-1].c, v+a[n-1].v, n-1));
	return memo[n][t]=ret;
}


int solve(int t)
{
	memo.clear();
	memo.resize(a.size()+1);
	for(int i=memo.size()-1;i>=0;i--)
	{
		memo[i].resize(t+1, -1);
	}
	return solve_r(t, 0, a.size());
}


int main(void)
{
	int t, n, i, j;
	vector<int> c, v, f;

	while(scanf("%d%d", &t, &n)==2)
	{
		a.clear();
		c.resize(n);
		v.resize(n);
		for(i=0;i<n;i++) scanf("%d", &c[i]);
		for(i=0;i<n;i++) scanf("%d", &v[i]);

		for(i=0;i<n;i++)
		{
			for(j=0;v[i]>>j;j++)
			{
				a.push_back((a_t){c[i], v[i]>>j});
			}
		}
/*
		for(i=0;i<a.size();i++) printf("%d %d\n", a[i].c, a[i].v);
		printf("a.size()=%d\n", a.size());
*/
		printf("%d\n", solve(t));
	}

	return 0;
}
0