标签:des style blog http color io os ar for
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <numeric> 6 #include <functional> 7 using namespace std; 8 typedef long long LL; 9 10 const int MAXN = 2010; 11 const int MOD = 1e9 + 7; 12 13 void update_add(int &a, int b) { 14 a += b; 15 if(a >= MOD) a -= MOD; 16 } 17 18 int a[MAXN][MAXN], sum[MAXN][MAXN]; 19 int b[MAXN]; 20 int n, s, T; 21 22 void solve() { 23 memset(a, 0, sizeof(a)); 24 s = accumulate(b, b + n, 0); 25 26 for(int i = 0; i <= b[0]; ++i) a[0][i] = 1; 27 sum[0][0] = a[0][0]; 28 for(int j = 1; j <= s; ++j) sum[0][j] = (sum[0][j - 1] + a[0][j]) % MOD; 29 30 for(int i = 1; i < n; ++i) { 31 for(int j = 0; j <= s; ++j) { 32 //for(int k = j - b[i]; k <= j; ++k) a[i][j] += a[i - 1][k]; 33 if(j - b[i] <= 0) a[i][j] = sum[i - 1][j]; 34 else a[i][j] = (sum[i - 1][j] - sum[i - 1][j - b[i] - 1] + MOD) % MOD; 35 } 36 sum[i][0] = a[i][0]; 37 for(int j = 1; j <= s; ++j) sum[i][j] = (sum[i][j - 1] + a[i][j]) % MOD; 38 } 39 } 40 41 void print() { 42 for(int j = 0; j <= s; ++j) 43 printf("%4d", j); 44 puts(""); 45 for(int i = 0; i < n; ++i) { 46 for(int j = 0; j <= s; ++j) 47 printf("%4d", a[i][j]); 48 puts(""); 49 } 50 } 51 52 int main() { 53 scanf("%d", &T); 54 while(T--) { 55 scanf("%d", &n); 56 for(int i = 0; i < n; ++i) scanf("%d", &b[i]); 57 sort(b, b + n); 58 solve(); 59 //print(); 60 printf("%d\n", a[n - 1][s / 2]); 61 } 62 }
HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/oyking/p/3970845.html