#include <cstdio> #include <vector> #include <algorithm> using namespace std; const int Q = ((int)1e9) + 7; void dod(int& x, int y) { x += y; if (x >= Q) x -= Q; } int mn(long long a, int b) { return a * b % Q; } const int M = 5013; int main() { vector<vector<int> > newt(M, vector<int>(M)); for (int i = 0; i < M; i++) { newt[i][0] = 1; for (int j = 1; j <= i; j++) { newt[i][j] = newt[i-1][j]; dod(newt[i][j], newt[i-1][j-1]); } } int n; scanf("%d", &n); vector<int> t(M); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); t[a]++; } vector<int> dp(M), e; dp[0] = 1; for (int i = 1; i < M; i++) if(t[i]) { for (int s = M-1; s >= i-1; s--) if(dp[s]) { int dps = dp[s]; for (int k = 1; k <= t[i]; k++) dod(dp[std::min(s + k * i, M-1)], mn(dps, newt[t[i]][k])); } // for (int s = 0; s < M; s++) if(dp[s]) printf("%d %d :: %d\n",i,s,dp[s]); } int ret = 0; for (int i = 1; i < M; i++) dod(ret, dp[i]); printf("%d\n",ret); 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int Q = ((int)1e9) + 7; void dod(int& x, int y) { x += y; if (x >= Q) x -= Q; } int mn(long long a, int b) { return a * b % Q; } const int M = 5013; int main() { vector<vector<int> > newt(M, vector<int>(M)); for (int i = 0; i < M; i++) { newt[i][0] = 1; for (int j = 1; j <= i; j++) { newt[i][j] = newt[i-1][j]; dod(newt[i][j], newt[i-1][j-1]); } } int n; scanf("%d", &n); vector<int> t(M); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); t[a]++; } vector<int> dp(M), e; dp[0] = 1; for (int i = 1; i < M; i++) if(t[i]) { for (int s = M-1; s >= i-1; s--) if(dp[s]) { int dps = dp[s]; for (int k = 1; k <= t[i]; k++) dod(dp[std::min(s + k * i, M-1)], mn(dps, newt[t[i]][k])); } // for (int s = 0; s < M; s++) if(dp[s]) printf("%d %d :: %d\n",i,s,dp[s]); } int ret = 0; for (int i = 1; i < M; i++) dod(ret, dp[i]); printf("%d\n",ret); return 0; } |