HDU5000 区间dp

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

这个题一开始我就在考虑各种条件,想过只有一个属性大一个属性小这样枚举
但是突然想到还要进行容斥…
再dfs一下肯定炸了
然后迷之想到了鸽巢原理加强版
两个属性和相同的东西肯定能存活
因为存在某个….就那个书上原话我记不清楚了
反正意思就是属性数总额相同并且不是完全相同的一定有个属性高有个低
这样问题就被简化了
直接找不同的属性总额存在多少个就行了
然后我又发现。。。
1被2覆盖了…
2被3覆盖了….
打了好几个表发现sum/2的时候竟然是最多的….
这样就变成了一个弱智区间dp…..
a1+…an=sum/2的解的个数就行了…
虽然还是wa了无数次
感觉自己真是个智障

#include<iostream>
#include<cmath>
#include<memory.h>
#include<cstdio>
#include<queue>
#include<string>
#include<algorithm>
int n;
int tu[2001];
int dp[2001][2001];
using namespace std;
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        memset(tu, 0, sizeof(tu));
        memset(dp, 0, sizeof(dp));
        cin >> n;
        int sum = 0;
        for (int a = 1;a <= n;a++)scanf("%d", &tu[a]), sum += tu[a];
        sum /= 2;
    //  for (int a = 1;a <= n;a++)dp[0][a] = 1;
        for (int a = 0;a <= tu[1];a++)
        {
            if (a > sum)break;
            dp[a][1] = 1;
        }
        for (int a = 2;a <= n;a++)
        {
            for (int b = 0;b <= sum;b++)
            {
                for (int c = 0;c <= tu[a];c++)
                {
                    if (c > b)break;
                    dp[b - c][a - 1] %=((int)(1e9 + 7));
                    dp[b][a] += dp[b - c][a - 1];
                    dp[b][a]%= ((int)(1e9 + 7));
                }
            }
        }
        cout << dp[sum][n] << endl;
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值