#include <iostream> #include <vector> #include <algorithm> #include <numeric> constexpr long long mod =1000000007; long long getNumberOfSubsets(std::vector<long long> candies) { std::sort(candies.begin(), candies.end()); std::vector<long long > sums(std::accumulate(candies.begin(), candies.end(),1),0); sums[0] = 1; for(const auto& candy:candies) { for(int s=sums.size()-candy-1;s>=candy-1; --s) { sums[s+candy]+=sums[s]; sums[s+candy]%=mod; } } long long count = -1; std::for_each(sums.begin(), sums.end(), [&](long long n) { count += n; count%=mod; }); return count; } int main() { std::ios_base::sync_with_stdio(false); int n; std::cin>>n; std::vector<long long> candies(n,0); for(int i=0;i<n;++i) std::cin>>candies[i]; std::cout<<getNumberOfSubsets(candies)<<std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include <iostream> #include <vector> #include <algorithm> #include <numeric> constexpr long long mod =1000000007; long long getNumberOfSubsets(std::vector<long long> candies) { std::sort(candies.begin(), candies.end()); std::vector<long long > sums(std::accumulate(candies.begin(), candies.end(),1),0); sums[0] = 1; for(const auto& candy:candies) { for(int s=sums.size()-candy-1;s>=candy-1; --s) { sums[s+candy]+=sums[s]; sums[s+candy]%=mod; } } long long count = -1; std::for_each(sums.begin(), sums.end(), [&](long long n) { count += n; count%=mod; }); return count; } int main() { std::ios_base::sync_with_stdio(false); int n; std::cin>>n; std::vector<long long> candies(n,0); for(int i=0;i<n;++i) std::cin>>candies[i]; std::cout<<getNumberOfSubsets(candies)<<std::endl; return 0; } |