求调 80pts
查看原帖
求调 80pts
923248
Lian_zy楼主2023/12/3 10:00
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 25, maxm = 2e3 + 10;
bool vis[maxn], dp[maxm];
int n, m, ans, tot, tmp, a[maxn];
void dfs(int cur, int sum) {
	if (sum > m) return ;
	if (cur == n) {
		if (sum == m) {
			memset(dp, 0, sizeof(dp));
			dp[0] = true;
			tot = tmp = 0;
			for (int i = 1; i <= n; i++) {
				if (vis[i]) continue;
				for (int j = tot; ~j; j--) {
					if (dp[j]) {
						if (dp[j + a[i]]) continue;
						dp[j + a[i]] = true;
						tmp++;
					}
				}
				tot += a[i];
			}
			ans = max(ans, tmp);
		}
		return ;
	}
	dfs(cur + 1, sum);
	vis[cur] = true;
	dfs(cur + 1, sum + 1);
	vis[cur] = false;
	return ;
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	dfs(1, 0);
	printf("%d\n", ans);
	return 0;
}
2023/12/3 10:00
加载中...