蒟蒻求助:#5#6#7#9WA!
查看原帖
蒟蒻求助:#5#6#7#9WA!
592476
sz_jinzikai楼主2023/4/15 22:03
# include <bits/stdc++.h>

# define old_six \
	ios::sync_with_stdio (0);\
	\
	cin.tie (0);\
	\
	cout.tie (0);

# define ffor(i,name) \
	for (auto i = name.begin (); i != name.end (); i ++)

# define iter(type) \
	type :: iterator

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

typedef pair <ll, ll> pll;

int t, n, a[105], m, minm;

bool dp[10005], ans[10005];

int main () {

	old_six

	cin >> t;

	while (cin >> a[n], a[n] >= 0)
		minm += a[n ++];

	ans[0] = 1;

	for (int i = 0; i < n; i ++)
		for (int j = minm; j; j --)
			ans[j] |= ans[j - a[i]];

	while (-- t) {

		n = m = 0;

		memset (dp, 0, sizeof dp);

		while (cin >> a[n], a[n] >= 0)
			m += a[n ++];

		dp[0] = 1;

		for (int i = 0; i < n; i ++)
			for (int j = m; j; j --)
				dp[j] |= dp[j - a[i]];

		minm = min (minm, m);

		for (int i = minm; i; i --)
			ans[i] &= dp[i];

	}

	for (int i = minm; i; i --)
		if (ans[i]) {

			cout << i;

			return 0;

		}

	cout << 0;

	return 0;

}

个人目前找不到错误

2023/4/15 22:03
加载中...