HDU 5000 clone (Discrete Mathematics + dp) (2014 ACM/ICPC Asia Regional Anshan online)

Source: Internet
Author: User
Problem descriptionafter eating food from Chernobyl, DRD got a super power: He cocould clone himself right now! He used this power for several times. he found out that this power was not as perfect as he wanted. for example, some of the cloned objects were tall, while some were short; some of them were fat, and some were thin.

More evidence showed that for two clones A and B, if a was no worse than B in all fields, then B cocould not keep ve. more specifically, DRD used a vector V to represent each of his clones. the vector V has n dimensions, representing a clone having N abilities. for the I-th dimension, V [I] is an integer between 0 and T [I], where 0 is the worst and T [I] is the best. for two clones a and B, whose corresponding vectors were p and q, if for 1 <= I <= N, P [I]> = Q [I], then B cocould not keep ve.

Now, as DRD's friend, ATM wants to know how many clones can have ve at most. inputthe first line contains an integer T, denoting the number of the test cases.

For each test case: the first line contains 1 integer N, 1 <=n <= 2000. the second line contains N integers indicating T [1], t [2],..., T [N]. it guarantees that the sum of T [I] in each test case is no more than 2000 and 1 <= T [I]. outputfor each test case, output an integer representing the answer MOD 10 ^ 9 + 7. definition vector x = {x1, x2 ,......, Xn}, y = {y1, Y2 ,......, Yn}, x ≥ y if and only if any I has xi ≥ Yi. If X is greater than or equal to Y, y cannot exist. First, let's give a vector T and ask how many vectors can coexist in all the vectors smaller than or equal to T. Train of Thought: Since no one is writing a question, let me write it ...... First, the set of all vectors smaller than or equal to T is a partial order relationship, and an anti-chain in the partial order relationship is a solution in the question, the longest anti-chain is the maximum solution required in the question. According to the Dilworth theorem, the longest anti-chain = the hidden chain overwrites the code to be continued (125 Ms ):
 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 }
View code

 

HDU 5000 clone (Discrete Mathematics + dp) (2014 ACM/ICPC Asia Regional Anshan online)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.