結果

問題 No.527 ナップサック容量問題
ユーザー mogurockermogurocker
提出日時 2017-10-15 23:28:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 766 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 161,152 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 22:05:01
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, V, dp[100005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	vector<P> vw(n);
	FOR(i, n) cin >> vw[i].first >> vw[i].second;
	cin >> V;
	FOR(i, n) {
		vector<int> _dp(V+2);
		FOR(j, V+2) {
			if (j-vw[i].first >= 0) _dp[j] = max(dp[j], dp[j-vw[i].first] + vw[i].second);
			else _dp[j] = dp[j];
		}
		FOR(j, V+2) dp[j] = _dp[j];
	}
	cout << dp[V] << endl;
	if (dp[V+1] == dp[V]) cout << "inf" << endl;
	else cout << dp[V+1]-1 << endl;
	return 0;
}
0