結果

問題 No.37 遊園地のアトラクション
ユーザー hiyokko2hiyokko2
提出日時 2016-08-05 20:56:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 816 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 158,436 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-18 19:51:24
合計ジャッジ時間 2,383 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,788 KB
testcase_01 AC 5 ms
8,832 KB
testcase_02 AC 6 ms
8,792 KB
testcase_03 AC 4 ms
8,820 KB
testcase_04 AC 4 ms
8,660 KB
testcase_05 AC 4 ms
8,632 KB
testcase_06 AC 5 ms
8,736 KB
testcase_07 AC 6 ms
8,488 KB
testcase_08 AC 4 ms
8,644 KB
testcase_09 AC 3 ms
8,816 KB
testcase_10 AC 7 ms
8,832 KB
testcase_11 AC 6 ms
8,632 KB
testcase_12 AC 5 ms
8,468 KB
testcase_13 AC 4 ms
8,680 KB
testcase_14 AC 5 ms
8,692 KB
testcase_15 AC 4 ms
8,676 KB
testcase_16 AC 4 ms
8,720 KB
testcase_17 AC 4 ms
8,808 KB
testcase_18 AC 6 ms
8,792 KB
testcase_19 AC 5 ms
8,732 KB
testcase_20 AC 5 ms
8,748 KB
testcase_21 AC 4 ms
8,704 KB
testcase_22 AC 4 ms
8,800 KB
testcase_23 AC 4 ms
8,548 KB
testcase_24 AC 3 ms
8,760 KB
testcase_25 AC 4 ms
8,744 KB
testcase_26 AC 5 ms
8,720 KB
testcase_27 AC 5 ms
8,568 KB
testcase_28 AC 4 ms
8,620 KB
testcase_29 AC 4 ms
8,552 KB
testcase_30 AC 4 ms
8,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int T, N;
int c[15], v[15];
int newN;
int newc[135], newv[135];
int dp[136][10001];

int rec(int i, int t)
{
	if (dp[i][t] >= 0) return dp[i][t];

	int res;
	
	if (i == newN)
	{
		res = 0;
	}
	else if (t < newc[i])
	{
		res = rec(i + 1, t);
	}
	else
	{
		res = max(rec(i + 1, t), rec(i + 1, t - newc[i]) + newv[i]);
	}

	return dp[i][t] = res;
}

signed main()
{
	cin >> T;
	cin >> N;
	rep(i,N) cin >> c[i];
	rep(i,N) cin >> v[i];

	newN = 0;
	rep(i,N)
	{
		while (v[i] > 0)
		{
			newc[newN] = c[i];
			newv[newN] = v[i];
			v[i] /= 2;
			newN++;
		}
	}

	/*
	printf("newN = %d\n", newN);
	rep(i,newN) printf("(%d, %d)\n", newc[i], newv[i]);
	*/

	memset(dp, -1, sizeof(dp));

	cout << rec(0, T) << endl;
}
0