結果

問題 No.2093 Shio Ramen
ユーザー MagentorMagentor
提出日時 2022-10-07 21:54:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 3,802 ms
コンパイル使用メモリ 197,280 KB
実行使用メモリ 11,460 KB
最終ジャッジ日時 2023-09-03 01:39:07
合計ジャッジ時間 3,720 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,400 KB
testcase_01 AC 5 ms
11,396 KB
testcase_02 AC 5 ms
11,404 KB
testcase_03 AC 5 ms
11,264 KB
testcase_04 AC 5 ms
11,224 KB
testcase_05 AC 5 ms
11,192 KB
testcase_06 AC 6 ms
11,244 KB
testcase_07 AC 5 ms
11,188 KB
testcase_08 AC 5 ms
11,188 KB
testcase_09 AC 7 ms
11,380 KB
testcase_10 AC 14 ms
11,460 KB
testcase_11 AC 6 ms
11,220 KB
testcase_12 AC 7 ms
11,292 KB
testcase_13 AC 6 ms
11,264 KB
testcase_14 AC 7 ms
11,324 KB
testcase_15 AC 13 ms
11,320 KB
testcase_16 AC 8 ms
11,260 KB
testcase_17 AC 8 ms
11,372 KB
testcase_18 AC 19 ms
11,336 KB
testcase_19 AC 14 ms
11,272 KB
testcase_20 AC 11 ms
11,252 KB
testcase_21 AC 12 ms
11,436 KB
testcase_22 AC 12 ms
11,288 KB
testcase_23 AC 18 ms
11,292 KB
testcase_24 AC 17 ms
11,256 KB
testcase_25 AC 17 ms
11,264 KB
testcase_26 AC 17 ms
11,252 KB
testcase_27 AC 18 ms
11,256 KB
testcase_28 AC 17 ms
11,256 KB
testcase_29 AC 18 ms
11,252 KB
testcase_30 AC 17 ms
11,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
long long wt[1005], val[1005];
long long dp[1005][1005];

long long func(int index, int wt_left) {
	if(wt_left==0) return 0;
	if(index<0) return 0;
	if(dp[index][wt_left]!=-1) return dp[index][wt_left];
	long long ans = func(index-1, wt_left);
	if(wt_left-wt[index]>=0)
	ans = max(ans, func(index-1, wt_left-wt[index]) + val[index]);
	return dp[index][wt_left] = ans;
}

int main() {
	memset(dp,-1,sizeof(dp));
	long long n,w;
	cin >> n >> w;
	for(int i=0; i<n; i++) {
		cin >> wt[i] >> val[i];
	}
	cout << func(n-1, w);
}

0