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. [dpdk] 读官方文档(2)

    续前节.切好继续: 一,文档里提到uio_pci_generic, igb_uio, vfio_pci三个内核模块,完全搞不懂,以及dpdk-devbind.py用来查看网卡状态,我得到了下边的输出: ...

  2. 抓包工具Charles 【转】

      今天就来看一下Mac上如何进行抓包,之前有一篇文章介绍了使用Fidder进行抓包 http://blog.csdn.net/jiangwei0910410003/article/details/1 ...

  3. sql 语句查询练习题

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. select sname,ssex,class from student 2. 查询教师所有的单位即不重复的Depart列 ...

  4. IE 的resize事件问题

    window的resize事件,真的让人无语! 我在动态设置元素的HTML内容后,窗口高度变化了,可是却不触发resize事件. 但是我在访问document.documentElement.scro ...

  5. 《黑客大曝光》实践部分——sql注入(7/8)

    SQL注入实践 由于<黑客大曝光>中涉及到形形色色的攻击方式,从软件到硬件,甚至还有物理锁的开锁教程,当中的很多教程很有趣,但是我没有相关的环境,实践起来不好操作,比如说,查点扫描我还可以 ...

  6. nodejs express测试

    1.页面请求 app.get('/list_user', function (req, res) { console.log("/list_user GET 请求"); //res ...

  7. 【Android开发学习笔记】【第四课】基础控件的学习

    通过一个简单的例子来学习下面几种控件: 1.TextView:简单的文本显示控件 2.EditText:可以编辑的文本框 3.Button:按钮 4.Menu:这里指的是系统的Menu 5.Toast ...

  8. 利用快速排序原理找出数组中前n大的数

    #include <stdio.h> #include <stdint.h> #include <stdlib.h> #define MAX_SIZE 400001 ...

  9. IOS的APNS和PushKit门道详述

    基本功 iOS在诞生之初为了最大程度的保证用户体验,做了一些高瞻远瞩且影响深远的设计.APNs(Apple Push Notification service)就是其中一项. 早期iOS设备的内存和C ...

  10. C/C++ 排序&&查找算法(面试)

    一.排序 1.冒泡排序 void BubbleSort(int array[],int n) { ; ; ; ; ;i<n - ;i++) /*外循环控制排序的总趟数*/ { flag = ; ...