社区讨论
吸了氧过的,求调,最后四个点T
P5020[NOIP 2018 提高组] 货币系统参与者 5已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lo2oeuch
- 此快照首次捕获于
- 2023/10/23 17:09 2 年前
- 此快照最后确认于
- 2023/10/23 17:09 2 年前
CPP
#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();
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...