#include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef LOCAL #define debug(...) __VA_ARGS__ #else #define debug(...) {} #endif const int mod = 1e9+7; int main(){ ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); int i; int n; cin>>n; int tab[n+1]; for (i = 1; i < n+1; i++) cin>>tab[i]; stable_sort(tab+1,tab+n+1); int m = max(2,tab[n]); int dp[n+1][m]; for (i = 0; i < m; i++) dp[0][i] = 0; dp[0][0] = 1; for (i = 1; i < n+1; i++){ for (int j = 0; j < m; j++) dp[i][j] = dp[i-1][j]; for (int j = tab[i]-1; j < m; j++){ if (j+tab[i] < m) dp[i][j+tab[i]] = (dp[i][j+tab[i]]+dp[i-1][j])%mod; else dp[i][m-1] = (dp[i][m-1]+dp[i-1][j])%mod; } } int wy = 0; for (i = 1; i < m; i++) wy = (wy+dp[n][i])%mod; cout<<wy<<"\n"; 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 35 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef LOCAL #define debug(...) __VA_ARGS__ #else #define debug(...) {} #endif const int mod = 1e9+7; int main(){ ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); int i; int n; cin>>n; int tab[n+1]; for (i = 1; i < n+1; i++) cin>>tab[i]; stable_sort(tab+1,tab+n+1); int m = max(2,tab[n]); int dp[n+1][m]; for (i = 0; i < m; i++) dp[0][i] = 0; dp[0][0] = 1; for (i = 1; i < n+1; i++){ for (int j = 0; j < m; j++) dp[i][j] = dp[i-1][j]; for (int j = tab[i]-1; j < m; j++){ if (j+tab[i] < m) dp[i][j+tab[i]] = (dp[i][j+tab[i]]+dp[i-1][j])%mod; else dp[i][m-1] = (dp[i][m-1]+dp[i-1][j])%mod; } } int wy = 0; for (i = 1; i < m; i++) wy = (wy+dp[n][i])%mod; cout<<wy<<"\n"; return 0; } |