diff --git a/src/P5020/P5020.cpp b/src/P5020/P5020.cpp new file mode 100644 index 0000000..9ac9b51 --- /dev/null +++ b/src/P5020/P5020.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +using ll = long long; + +struct ReadLL{ + char c; + ll w,n; + ReadLL&operator>>(ll &num){ + c=0,w=1,n=0; + while(!isdigit(c)){ + if(c=='-')w=-1; + c=getchar(); + } + while(isdigit(c)){ + n=n*10+c-'0'; + c=getchar(); + } + num=n*w; + return *this; + } +}readll; + +auto &is = readll; +auto &os = std::cout; + +const ll max_n{100+5},max_a=2.5e4+5; +ll t, n, a[max_n], ans; +std::bitset dp; + +int main(){ + is>>t; + for(ll _{0};_>n; + ans=n; + for(ll i{1};i<=n;i++){ + is>>a[i]; + } + std::sort(a+1,a+n+1); + dp.reset(); + dp[0]=1; + for(ll i{1};i<=n;i++){ + if(dp[a[i]]){ + ans--; + continue; + } + for(ll j{a[i]};j<=a[n];j++){ + dp[j]=dp[j]||dp[j-a[i]]; + } + } + os<