吸了氧过的,求调,最后四个点T
查看原帖
吸了氧过的,求调,最后四个点T
312605
Megumimwf楼主2023/4/30 15:12
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rl register long long
#define ws putchar(' ')
#define wl putchar('\n')

template <class T>

inline void read(T &res){
	char ch; bool flag = 0;
	while((ch = getchar()) < '0' || ch > '9'){
		if(ch == '-') flag = 1;
	}
	res = (ch ^ 48);
	while((ch = getchar()) <= '9' && ch >= '0'){
		res = (res << 1) + (res << 3) + (ch ^ 48);
	}
	if(flag) res = ~res + 1;
}

inline void w(ll x){
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) w(x/10);
	putchar(x%10+'0');
}

const ll N = 510;

ll n, t, a[N], tot, f[N*N];

inline ll pd(ll x){
	memset(f, 0, sizeof(f));
	for(rl i=1;i<=n;++i){
		for(rl j=a[i];j<=x;++j){
			if(a[i] == x) continue;
			f[j] = max(f[j], f[j-a[i]]+a[i]);
		}
	}
	if(f[x] == x) return 1;
	else return 0;
}

inline void realmain(){
	read(n);
	memset(a, 0, sizeof(a));
	for(rl i=1;i<=n;++i){
		read(a[i]);
	}
	stable_sort(a+1, a+1+n);
	tot = n;
	for(rl i=1;i<=n;++i){
		if(pd(a[i])){
			tot--;
		}
	}
	w(tot), wl;
}

int main(){
	read(t);
	while(t--) realmain();
}
2023/4/30 15:12
加载中...