题解
等价于线性代数中求最大无关组的大小
code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[105]={0};
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
int dp[25005]={1},num=0;
for(int i=1;i<=n;i++)
{
int is=0;
for(int j=0;j+a[i]<=a[n];j++) if(dp[j]&&!dp[j+a[i]]) dp[j+a[i]]=is=1;
num+=is;
int cnt=0;
for(int j=1;j<=n;j++) cnt+=dp[a[j]];
if(cnt==n) break;
}
cout<<num<<endl;
}
return 0;
}
标签:code,int,题解,cin,NOIP2018,货币,P5020
From: https://www.cnblogs.com/pure4knowledge/p/18052904