HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)

Problem Description

After eating food from Chernobyl, DRD got a super power: he could 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 could not survive. 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 could not survive.

Now, as DRD‘s friend, ATM wants to know how many clones can survive at most.

Input

The 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].

Output

For each test case, output an integer representing the answer MOD 10^9 + 7.

题目大意:定义向量x = {x1, x2, ……, xn}, y = {y1, y2, ……, yn},有x ≥ y当且仅当对于任意 i 都有 xi ≥ yi。如果x ≥ y,那么 y 不能存在。先给一个向量T,问所有小于等于T的向量中,最多有多少个向量可以共存。

思路:既然没有人写题解,我来写一下……

首先,所有小于等于T的向量的集合,是一个偏序关系,偏序关系中的一条反链就是题目中的一个解,而最长反链就是题目中要求的最大解

根据Dilworth定理,最长反链 = 最小链覆盖

未完待续

代码(125MS):

 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 }

时间: 2024-10-15 01:54:27

HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)的相关文章

HDU 5000 Clone 规律+dp 2014 ACM/ICPC Asia Regional Anshan Online

每只羊有n个属性 下面n个数字表示每个属性的值范围为[ 0, T[i] ] 对于羊圈里的a羊和b羊,若a羊的每个属性都>=b羊,则a羊会杀死b羊. 问羊圈里最多存活多少只羊. 规律1:sum相同的羊不会互相杀死. 因为若2个羊的属性都相同,a羊某个属性要增加1,则a羊另一个属性要减少1,这样ab一定能共存. 规律2: sum不同的羊不会重合. 我们设a羊sum = x,b羊sum = y,若a,b羊能共存,但不会把ab同时放到羊圈里. 因为一定存在一只羊c ,sum = x,且c和b不能共存,既

HDU 5001 Walk 求从任意点出发任意走不经过某个点的概率 概率dp 2014 ACM/ICPC Asia Regional Anshan Online

题意: 给定n个点m条边的无向图 问: 从任意点出发任意走d步,从不经过某个点的概率 dp[i][j]表示从不经过i点的前提下,走了d步到达j点的概率. #include <iostream> #include <cstdio> #include <string.h> #include <queue> #include <vector> #include <algorithm> #include <set> using n

HDU 5003 Osu! 水题 2014 ACM/ICPC Asia Regional Anshan Online

水.. #include <iostream> #include <cstdio> #include <string.h> #include <queue> #include <vector> #include <algorithm> #include <set> using namespace std; #define N 100 double a[N]; bool cmp(double x, double y){ re

HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP

Clone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Submission(s) : 8   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description After eating food from Chernobyl,

HDU 5014 Number Sequence 贪心 2014 ACM/ICPC Asia Regional Xi&#39;an Online

尽可能凑2^x-1 #include <cstdio> #include <cstring> const int N = 100005; int a[N], p[N]; int init(int x) { int cnt = 0; while(x > 1) { x /= 2; cnt ++; } return cnt + 1; } int main() { int n; while(~scanf("%d", &n)){ for(int i = 0;

HDU 5010 Get the Nut(2014 ACM/ICPC Asia Regional Xi&#39;an Online)

思路:广搜, 因为空格加上动物最多只有32个那么对这32个进行编号,就能可以用一个数字来表示状态了,因为只有 ‘P’   'S' 'M' '.' 那么就可以用4进制刚好可以用64位表示. 接下去每次就是模拟了. 注意:  ‘S’ 不是只有一个. 一个东西如果不是'P'在动的话要先判断周围有没有‘P’,有的话要先吃掉      'P'在动的时候如果一个位置周围有多个东西,都要吃掉. #include<iostream> #include<cstdio> #include<alg

poj 5001 Walk &amp;&amp;2014 ACM/ICPC Asia Regional Anshan Online 1005(dp)

http://acm.hdu.edu.cn/showproblem.php?pid=5001 思路:dp计算出途径每个点的总概率,1-x即为所求解. dp题,先介绍下dp[i][j]为第j步走在第i个点的概率,那么dp[i][j]=dp[x1][j-1]+dp[x2][j-1]+...,x1,x2为i 的相邻节点.上一步在相邻节点这一步才能走到该点嘛. 每个点概率要一个一个的算,当算到第ii个点时(没打错,ii个点与代码对应),从起点推起,起点嘛,算是第0步吧,每个点被选中几率1.0/n,直接计

HDU 4998 Rotate 计算几何 2014 ACM/ICPC Asia Regional Anshan Online

题意: 有一个平面放在一个二维坐标轴上 给定n个操作 (x,y) p 表示把平面绕着(x,y) 逆时针转p弧度. 最后的结果相当于平面绕着(X, Y) 逆时针旋转了P弧度. 求:X,Y,P 思路: 任取一个三角形ABC,然后根据n个操作得到A'B'C', 然后求外心. 旋转的角度就是相加..==为啥我也不大清楚,不是本弱写的. #include <cstdio> #include <algorithm> #include <iostream> #include <

HDU 5002 Tree(动态树LCT)(2014 ACM/ICPC Asia Regional Anshan Online)

Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node is associated with an integer as the weight. Your task is to deal with M operations of 4 types: 1.Delete an edge (x, y) from the tree, and then add a