货币系统
题目
解析
答案显然,直接上bool数组判一下可行,直接dp即可
code:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[110],n,T,ans;
bool dp[25010];
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n),ans=n,memset(dp,0,sizeof(dp)),dp[0]=1;
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(int i=1;i<=n;++i){ans-=dp[a[i]];for(int j=a[i];j<=a[n];++j)dp[j]|=dp[j-a[i]];}
printf("%d\n",ans);
}
return 0;
}