hdu 5000 Clone (dp + 找规律)

Clone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 820    Accepted Submission(s): 403

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.

Sample Input

2
1
5
2
8 6

Sample Output

1
7

题意:每只羊有n个属性,下面n个数字表示每个属性的值范围为[ 0, T[i] ]对于羊圈里的a羊

和b羊,若a羊的每个属性都>=b羊,则a羊会杀死b羊。问羊圈里最多存活多少只羊。

思路:要推出最大值的时候,每个人的属性和必然相同,并且这个和必然是所有和 / 2,这

样的话,问题转化为给n个数字,要组合成sum / 2有多少种方法,就用dp背包推一遍就可

以得解了。

#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
using namespace std;
const LL mod=1000000007;
const int maxn=2010;

int a[maxn],sum,n;
LL dp[maxn];

void input()
{
    scanf("%d",&n);
    sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sum/=2;
}

void solve()
{
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=1;i<=n;i++)
        for(int k=sum;k>=1;k--)
            for(int j=1;j<=a[i];j++)
                if(k-j>=0)
                    dp[k]=(dp[k]+dp[k-j])%mod;
    printf("%I64d\n",dp[sum]);
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
         input();
         solve();
    }
    return 0;
}
时间: 2024-07-28 21:37:40

hdu 5000 Clone (dp + 找规律)的相关文章

hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定要矩阵快速幂.然后立马GG. 用2代表m,1代表f.设dp[i][j][k]表示,在第i位,上一位站了的人是j,这一位站的人是k,的合法情况. 递推过去就是,如果j是1,k是2,那么这一位就只能放一个2,这个时猴dp[i][k][2] += dp[i - 1][j][k]; 其他情况分类下就好,然后

HDU 5000 Clone(鞍山网络赛D题)

HDU 5000 Clone 这场就出了3题..就坑在这题上了,还好保住了名额 思路:要推出最大值的时候,每个人的属性和必然相同,并且这个和必然是所有和 / 2,这样的话,问题转化为给n个数字,要组合成sum / 2有多少种方法,就用dp背包推一遍就可以得解了. 现场的时候就没推出sum / 2就是答案 代码: #include <cstdio> #include <cstring> const int MOD = 1000000007; const int N = 2005; i

hdu 4952 Number Transformation (找规律)

题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值,求出这个固定的值和K相乘就可以了, 为什么会趋于固定的值呢,因为最后虽然i在不断增长,但是x也是在增长的,每次的倍数会回退一个发现 有余数,然后再加上一个,所以趋于稳定. 官方题解: 1 #include <iostream> 2 #include <cstdio> 3 #includ

hdu 4861 Couple doubi (找规律 )

题目链接 可以瞎搞一下,找找规律 题意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+?+(p−1)i%p,两个人轮流取,如果DouBiNan的值大的话就输出YES,否则输出NO. 分析:解题报告 1 #include <cstdio> 2 #include <iostream> 3 4 using namespace std; 5 int main() 6 { 7 int k, p; 8 while(cin>>k>>p) 9 { 10 if(k/

HDU 4927 Series (找规律+JAVA)

题目链接:HDU 4927 Series 题意:给出一串N个元素的序列,作为第一串序列,第二串序列是第二串序列相邻元素的查值(即Bi=Ai+1-Ai)...第三串....一直到第N-1串是序列中只有一个数. 刚开始想到模拟一发,WA了一把,推出公式,发现是二项展开的系数(正负交替).组合数,果断要大数,苦逼JAVA不会.和一起队友摸索着,又T了一发,再想到组合数的递推.终于A了 C(a-1,b)=C(a,b)*a/(b-a+1) AC代码: import java.math.BigInteger

HDU 4919 打表找规律 java大数 map 递归

== oeis: 点击打开链接 瞎了,x.mod(BigInteger.ValueOf(2)).equal( BigInteger.ValueOf(1)) 写成了 x.mod(BigInteger.ValueOf(2)).equal( 1 ) T^T100块没了... import java.math.*; import java.util.*; import static java.lang.System.out; import java.io.*; public class Main { s

HDU 4861 Couple doubi(找规律|费马定理)

Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4861 Description DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of th

[FJOI2007]轮状病毒 题解(dp(找规律)+高精度)

[FJOI2007]轮状病毒 题解(dp(找规律)+高精度) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1335733 没什么好说的,直接把规律找出来,有两种规律(据说还有多种dp),再套个高精度 \(First\) \(f[1]=1,f[2]=5,f[i]=3×f[i-1]-f[i-2]+2\) 就直接写个高精+低精和高精×低精和高精-高精就行了 \(Second\) \(f[1]=1,f[2]=3,f[i]=f[i-1]+f[i-2]\) \(i

HDU 5000 Clone(瞎搞)

题目地址:HDU 5000 这个题当时有过这种想法,就是所有满足的情况的属性和是一定的.但是不会求方案数..(太弱...)而且当时也很不确定猜测是否正确..所以就放下了...算是通过学习了下dp求方案数吧. 至于那个猜测,我也给不出证明,但是个人觉得是只有在和都是相等的时候,才可以通过某一个数的增减来始终保持至少有一个较大的,至少有一个较小的,而假如和不一样的话,就会产生其中一个会消灭另一个的情况.所以就转换成了和是多少的情况下方案数最大.很明显能够猜的出来是和的一半的时候(同样不会证明...看