zoukankan      html  css  js  c++  java
  • 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, 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
    

    Source

    2014 ACM/ICPC Asia Regional Anshan Online
    题意:
       给出每个羊有n个属性,对于A羊B羊,如果所有i(1<=i<=n) A[i]>=B[i] 则B羊能存活,问你最多能有几只羊同时存活
    题解:
      所有存活的情况的羊的都能划分为属性和相同的情况
      dp[i][j]表示前i只羊属性总和为j的方案数

    可以发现sum = 0 和 sum = 求和的方案数是一样的。

    同理sum其实是对称的,和组合数一样。所以dp[n][sum / 2] 是最大的。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    #include<map>
    using namespace std ;
    typedef long long ll;
    #define mod 1000000007
    #define inf 100000
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //******************************************************************
    int T,n,a[2005];
    int dp[2005][2005];
    int main()
    {
        scanf("%d",&T);
            while(T--){
                scanf("%d",&n);
                int  sum=0;
                for(int i=1;i<=n;i++)
                {
                    scanf("%d",&a[i]);
                    sum+=a[i];
                }
                memset(dp,0,sizeof(dp));
                for(int i=0;i<=a[1];i++)
                {
                    dp[1][i]=1;
                }
                for(int i=2;i<=n;i++)
                {
                    for(int j=0;j<=sum;j++)
                    {
                        for(int k=0;k<=a[i]&&j+k<=sum;k++)
                        {
                            dp[i][j+k]=(dp[i][j+k]+dp[i-1][j])%mod;
                        }
                    }
                }
                cout<<dp[n][sum/2]<<endl;
            }
        return 0;
    }
    代码
  • 相关阅读:
    由当前acitivty直接退到桌面
    Android中SharedPreference多进程数据共享出错
    java回调机制
    Android 监听apk安装替换卸载广播
    jquery中如何退出each循环
    旋转六面体源码
    用CSS3制作的旋转六面体动画
    CSS中常用的字体单位:px、em、rem和%的区别
    css属性简写集合
    小游戏--别踩白块
  • 原文地址:https://www.cnblogs.com/zxhl/p/4780959.html
Copyright © 2011-2022 走看看