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定理,最长反链 = 最小链覆盖
我们来看一下题目中的偏序集长什么样:
(不要吐槽图歪歪扭扭的)
于是,显然最小链覆盖取决于最多结点的一行。
而每个有边相连的结点,都只是差一个 1 ,所以每一行里的向量的和都是一样的。
所以题目就变成,设和为 x 的数的小于等于T的向量个数为cnt(x),求max{cnt(x), x = 1..sum{Ti}}
本来简单DP出来之后,可以直接取最大值,但是这题求出来的是模的结果,就不行了。
简单打表可以发现,最大的和总是cnt(sum{Ti} / 2),这个是可以证明的,这里不证了……
 
代码(125MS):
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <functional>
using namespace std;
typedef long long LL; const int MAXN = ;
const int MOD = 1e9 + ; void update_add(int &a, int b) {
a += b;
if(a >= MOD) a -= MOD;
} int a[MAXN][MAXN], sum[MAXN][MAXN];
int b[MAXN];
int n, s, T; void solve() {
memset(a, , sizeof(a));
s = accumulate(b, b + n, ); for(int i = ; i <= b[]; ++i) a[][i] = ;
sum[][] = a[][];
for(int j = ; j <= s; ++j) sum[][j] = (sum[][j - ] + a[][j]) % MOD; for(int i = ; i < n; ++i) {
for(int j = ; j <= s; ++j) {
//for(int k = j - b[i]; k <= j; ++k) a[i][j] += a[i - 1][k];
if(j - b[i] <= ) a[i][j] = sum[i - ][j];
else a[i][j] = (sum[i - ][j] - sum[i - ][j - b[i] - ] + MOD) % MOD;
}
sum[i][] = a[i][];
for(int j = ; j <= s; ++j) sum[i][j] = (sum[i][j - ] + a[i][j]) % MOD;
}
} void print() {
for(int j = ; j <= s; ++j)
printf("%4d", j);
puts("");
for(int i = ; i < n; ++i) {
for(int j = ; j <= s; ++j)
printf("%4d", a[i][j]);
puts("");
}
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = ; i < n; ++i) scanf("%d", &b[i]);
sort(b, b + n);
solve();
//print();
printf("%d\n", a[n - ][s / ]);
}
}

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

  1. HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP

    Clone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Submiss ...

  2. HDU 5010 Get the Nut(2014 ACM/ICPC Asia Regional Xi'an Online)

    思路:广搜, 因为空格加上动物最多只有32个那么对这32个进行编号,就能可以用一个数字来表示状态了,因为只有 ‘P’   'S' 'M' '.' 那么就可以用4进制刚好可以用64位表示. 接下去每次就 ...

  3. 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 ...

  4. 2014 ACM/ICPC Asia Regional Anshan Online

    默默的签到 Osu! http://acm.hdu.edu.cn/showproblem.php?pid=5003 #include<cstdio> #include<algorit ...

  5. hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)

    Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online)

    HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showp ...

  7. HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...

  8. 2014 ACM/ICPC Asia Regional Xi'an Online(HDU 5007 ~ HDU 5017)

    题目链接 A题:(字符串查找,水题) 题意 :输入字符串,如果字符串中包含“ Apple”, “iPhone”, “iPod”, “iPad” 就输出 “MAI MAI MAI!”,如果出现 “Son ...

  9. HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online

    意甲冠军: 特定n小点的树权. 以下n每一行给出了正确的一点点来表达一个销售点每只鸡价格的格 以下n-1行给出了树的侧 以下Q操作 Q行 u, v, val 从u走v,程中能够买一个鸡腿,然后到后面卖 ...

随机推荐

  1. HBase学习笔记-基础(一)

    HBase版本:0.97 1.Get Gets实在Scan的基础上实现的. 2.联合查询(Join) HBase是否支持联合是一个网上常问问题.简单来说 : 不支持.至少不像传统RDBMS那样支持. ...

  2. php比较加赋值语句

    $a=-2;if ($a < 0 && $a = 1) { echo $a;} 输出1 右面的$a=1可不是条件哦,而是赋值

  3. hive中关于数据库与表等的基本操作

    一:基本用法 1.新建数据库 2.删除数据库 3.删除非空的数据库 4.指定数据库的位置 LOCATION:指定数据库的位置,不会在系统的默认文件下. 5.在指定数据库中新建表(验证在指定的数据库中可 ...

  4. MVVM with ReactiveCocoa

    内容提要: 本文首先对比MVC简单介绍了MVVM的概念和优点,其次,简单介绍了Reactive Cocoa的使用,最后,通过一个例子介绍了使用Reactive Cocoa的MVVM框架. 正文: 首先 ...

  5. ligerui做分页显示数据

    现在前台技术用到的是ligerui,一直想写一个有关ligerui的显示,利用加班的今天偷点闲复制一下下,当自己的一些小资料吧,不会的时候,还可以来看看............稍微有点多,毕竟是从前后 ...

  6. LightOj1418 - Trees on My Island(Pick定理)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1418 题意:给你多边形中的顶点,n个点按顺时针或逆时针方向给出,然后求出多边形内部有多 ...

  7. Object转换为json格式

    public String toJSONString(Object obj)     {              SerializeWriter serializewriter = new Seri ...

  8. groovy

    1.加载和卸载(每次都新建一个GroovyClassLoader 实例,然后使用新建的classloader去加载) try { GroovyClassLoader groovyClassLoader ...

  9. iOS:iOS开发非常全的三方库、插件等等

    iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...

  10. 右键TXT文件-打开方式-选择默认程序提示 windows无法访问指定设备,路经或文件.您可能没有合适的权限访问这个项目

    新建立一个.txt文本,把下面复制到.txt文本点保存,再把.txt文件格式修改为.reg格式, 双击导入注册表就OK了 Windows Registry Editor Version 5.00 [H ...