#include <iostream> #include <algorithm> const int MAXN = 5005; const int MOD = 1000000007; int A[MAXN]; int S[MAXN]; int n; int main() { std::ios_base::sync_with_stdio(0); std::cin >> n; for (int i=0;i<n;++i) std::cin >> A[i]; std::sort(A, A+n); int max = A[n-1]+1; S[0] = 1; for (int i=0;i<n;++i) { for (int j=max;j>=A[i]-1;--j) { auto& t = S[std::min(max, j+A[i])]; t = (t+S[j])%MOD; } } int sum = 0; for (int i=1;i<=max;++i) sum = (sum + S[i]) % MOD; std::cout << sum << 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 | #include <iostream> #include <algorithm> const int MAXN = 5005; const int MOD = 1000000007; int A[MAXN]; int S[MAXN]; int n; int main() { std::ios_base::sync_with_stdio(0); std::cin >> n; for (int i=0;i<n;++i) std::cin >> A[i]; std::sort(A, A+n); int max = A[n-1]+1; S[0] = 1; for (int i=0;i<n;++i) { for (int j=max;j>=A[i]-1;--j) { auto& t = S[std::min(max, j+A[i])]; t = (t+S[j])%MOD; } } int sum = 0; for (int i=1;i<=max;++i) sum = (sum + S[i]) % MOD; std::cout << sum << std::endl; return 0; } |