新思路:bitset 解决问题
查看原帖
新思路:bitset 解决问题
799877
AK_heaven楼主2024/1/26 09:54

本人代码:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5;

bitset<maxn+1> S;
int n, x[maxn];
int main() {
	cin >> n;
	S[0] = 1;
	for(int i = 1; i <= n; i++)
	  cin >> x[i];
	sort(x+1, x+n+1);
	for(int i = 1; i <= n; i++)
	  for(int j = x[i]; j <= 1000; j++)
	    S |= S << x[i];
	int ans = 0; 
	for(int i = 1; i <= x[n]*990; i++)
	  if(!S.test(i)) ans++;
	if(ans > x[n]*500) cout << "INF";
	else cout << ans;
	return 0;
}
2024/1/26 09:54
加载中...