結果

問題 No.527 ナップサック容量問題
ユーザー rodearodea
提出日時 2018-03-02 18:54:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 68,980 KB
実行使用メモリ 44,036 KB
最終ジャッジ日時 2023-09-02 12:50:24
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,820 KB
testcase_01 AC 4 ms
4,964 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 16 ms
19,336 KB
testcase_06 AC 33 ms
37,852 KB
testcase_07 AC 35 ms
31,676 KB
testcase_08 AC 14 ms
17,284 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 43 ms
37,816 KB
testcase_11 AC 23 ms
27,540 KB
testcase_12 AC 18 ms
21,464 KB
testcase_13 AC 33 ms
37,776 KB
testcase_14 AC 18 ms
17,484 KB
testcase_15 AC 26 ms
23,432 KB
testcase_16 AC 5 ms
4,916 KB
testcase_17 AC 23 ms
21,380 KB
testcase_18 AC 25 ms
23,484 KB
testcase_19 WA -
testcase_20 AC 19 ms
17,288 KB
testcase_21 AC 50 ms
44,036 KB
testcase_22 AC 34 ms
29,588 KB
testcase_23 AC 49 ms
41,864 KB
testcase_24 AC 12 ms
11,196 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 31 ms
27,664 KB
testcase_28 WA -
testcase_29 AC 49 ms
43,996 KB
testcase_30 AC 6 ms
7,176 KB
testcase_31 AC 22 ms
21,528 KB
testcase_32 AC 28 ms
25,548 KB
testcase_33 AC 23 ms
21,392 KB
testcase_34 AC 28 ms
25,620 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;

int v[110], w[110];
int dp[110][100010]; 

pair<int, int> solve(int n, int V, pair<int, int>P)
{
	P = make_pair(1000000, 0);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= 100001; j++)
		{
			if (j < w[i]) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);

			if (dp[i][j] == V)
			{
				P.first = min(P.first, j);
				P.second = max(P.second, j);
			}
		}
	}
	return P;
}

int main()
{
	int n, V;
	pair<int, int> P;

	cin >> n;

	for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];

	cin >> V;

	cout << solve(n, V, P).first << endl;
	if(solve(n, V, P).second != 100001) cout << solve(n, V, P).second << endl;
	else cout << "inf" << endl;
}
0