题目链接:https://www.luogu.org/problem/P5020
题目大意为:在给出的一个有n种面值,面值的集合为a的货币系统中,我们可以称之为(n,a)货币系统,而我们定义两种货币系统是相等的,必须两个货币系统能够表示的货币情况都是相同的。
解题思路:我们先把货币面值先按照从小到大排序,如果大的面值能够由一些比它小的面值的货币组合起来,那么我们就可以删掉这种面值的货币(卑微的博主表示,货币不要可以给有需要的人啊,呜呜呜)。因为我们可以用其他面值的组合来代替这种面值,所以DP一下就可以啦。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
void read(int &x)
{
char c;
int f=1;
x=0;
c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0' && c<='9'){
x=x*10+c-'0';
c=getchar();
}
//return x*f;
}
bitset<maxn> now;
int a[maxn],c[maxn],pri[maxn];
int main()
{
int t;
read(t);
while(t--){
int n,len=0;
read(n);
now.reset();
now.set(0);
int ma=0;
for(int i=1;i<=n;i++){
read(a[i]);
ma=max(a[i],ma);
}
int ans=0;
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
if(now.test(a[i])==1)continue;
ans++;
for(int j=1;j*a[i]<=ma;j++){
now|=now<<a[i];
}
}
printf("%d\n",ans);
}
}