結果

問題 No.527 ナップサック容量問題
ユーザー aaaaaa
提出日時 2018-11-11 13:54:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,951 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 99,768 KB
実行使用メモリ 5,936 KB
最終ジャッジ日時 2023-08-19 22:14:17
合計ジャッジ時間 3,209 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;


int main() {
	int i, j;
	int n, V;
	vector<int>v, w;
	//vector<int>dp(100005, 0);
	vector<vector<int>>dp(105, vector<int>(1005, 0));
	vector<vector<int>>flag(100005);

	cin >> n;

	for (i = 0; i < n; i++) {
		int num1, num2;
		cin >> num1 >> num2;
		v.push_back(num1);
		w.push_back(num2);
		//dp[num2] = num1;
		//flag[num2].push_back(i);
	}

	cin >> V;


	for (i = 0; i < n; i++) {

		dp[i][w[i]] = max(dp[i][w[i]], v[i]);

		//for (int W = 1; W <= 1000; W++) {
		for (int W = 1000; W >= 1; W--) {
			if (W >= w[i]) {
				dp[i + 1][W] = max(dp[i][W], dp[i][W - w[i]] + v[i]);
			}
			else {
				dp[i + 1][W] = dp[i][W];
			}
		}
	}

	int maxn = -1, minn = 99999999;

	for (i = 1; i <= 1000; i++) {
		if (dp[n][i] == V) {
			maxn = max(maxn, i);
			minn = min(minn, i);
		}
		
	}

	cout << minn << endl;
	if (maxn >= 1000) {
		cout << "inf" << endl;
	}
	else {
		cout << maxn << endl;
	}


	////dp[0] = 1;

	//for (int W = 1; W <= 100000; W++) {

	//	bool flag2 = false;
	//	for (i = 0; i < n; i++) {
	//		if (W >= w[i]) {

	//			if (W - w[i] != 0 && dp[W - w[i]] == 0) {
	//				continue;
	//			}
	//			int num = 0;
	//			/*	if (dp[W - w[i]] == 0) {
	//					num = 0;
	//				}
	//				else {*/
	//			auto itr = std::find(flag[W - w[i]].begin(), flag[W - w[i]].end(), i);
	//			if (itr != flag[W - w[i]].end()) {
	//				//dp[W] = dp[W - 1];
	//				//flag[W] = flag[W - 1];
	//				continue;
	//			}
	//			else {
	//				num = dp[W - w[i]] + v[i];
	//				//if (W - w[i] != 0) {
	//					//flag[W - w[i]].push_back(i);
	//				flag[W].push_back(i);
	//				//}
	//				//flag[W - w[i]].push_back(i);
	//				//flag[W] = flag[W - w[i]];
	//				//flag[W].push_back(i);
	//				//flag[W].push_back(flag[W - w[i]]);
	//			}
	//			//}
	//			if (num > dp[W - 1]) {
	//				dp[W] = num;
	//				flag2 = true;
	//			}
	//			else if (num < dp[W - 1]) {
	//				//dp[W] = dp[W - 1];
	//				//flag[W] = flag[W - 1];
	//			}

	//			//dp[W] = max({ dp[W], num, dp[W - 1] });

	//		}
	//	}

	//	if (flag2 == false) {
	//		dp[W] = dp[W - 1];
	//		flag[W] = flag[W - 1];
	//	}

	//}

	//vector<int>list;

	//for (i = 0; i <= 1000; i++) {
	//	if (dp[i] == V) {
	//		list.push_back(i);
	//	}
	//}

	//sort(list.begin(), list.end());

	//if (list.size() >= 1 && list[0] == 0){
	//	list.erase(list.begin());
	//}

	//if (list.size() == 0) {

	//}
	//else {
	//	
	//	int minn = list[0];
	//	cout << minn << endl;

	//	//if (list[list.size() - 1] == dp[minn]) {
	//	if (dp[999] == dp[minn]) {
	//		cout << "inf" << endl;
	//	}
	//	else {
	//		cout << list[list.size() - 1] << endl;
	//	}

	//}
	


	getchar();
	getchar();
	return 0;
}
0