HDU 5000 Clone 规律+dp 2014 ACM/ICPC Asia Regional Anshan Online

每只羊有n个属性

下面n个数字表示每个属性的值范围为[ 0, T[i] ]

对于羊圈里的a羊和b羊,若a羊的每个属性都>=b羊,则a羊会杀死b羊。

问羊圈里最多存活多少只羊。

规律1:sum相同的羊不会互相杀死。

因为若2个羊的属性都相同,a羊某个属性要增加1,则a羊另一个属性要减少1,这样ab一定能共存。

规律2:

sum不同的羊不会重合。

我们设a羊sum = x,b羊sum = y,若a,b羊能共存,但不会把ab同时放到羊圈里。

因为一定存在一只羊c ,sum = x,且c和b不能共存,既然不能共存,则我们放入c羊是不会影响答案的。

所以dp[i][j]表示前i只羊 sum 为 j 时的方案数。

但我们结果是要mod的,所以不能给所有sum取最大值。

可以发现sum = 0 和 sum = 求和(T[i]) 的方案数是一样的。

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

#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
#define N 2005
typedef long long ll;
const ll mod = 1000000007LL;

int n;
ll dp[N][N];
int a[N],sum;
ll solve(){
	if(n == 1)return 1LL;
	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 + j <= sum && k <= a[i]; k++)
			{
				dp[i][k+j] = (dp[i][k+j] + dp[i-1][j]) % mod;
			}
		}
	}
	return dp[n][sum];
}
int main(){
	int T;scanf("%d",&T);
	while(T--){
		scanf("%d", &n);
		for(int i = 1; i <= n; i++)
			scanf("%d", &a[i]);

		sum = 0;
		for(int i = 1; i <= n; i++)
			sum += a[i];
		sum /= 2;

		cout<<solve()<<endl;
	}
	return 0;
}
/*
99
1
5
2
8 6
3
3 2 2
3
2 2 2

*/
时间: 2024-08-02 11:03:09

HDU 5000 Clone 规律+dp 2014 ACM/ICPC Asia Regional Anshan Online的相关文章

HDU 5001 Walk 求从任意点出发任意走不经过某个点的概率 概率dp 2014 ACM/ICPC Asia Regional Anshan Online

题意: 给定n个点m条边的无向图 问: 从任意点出发任意走d步,从不经过某个点的概率 dp[i][j]表示从不经过i点的前提下,走了d步到达j点的概率. #include <iostream> #include <cstdio> #include <string.h> #include <queue> #include <vector> #include <algorithm> #include <set> using n

HDU 5003 Osu! 水题 2014 ACM/ICPC Asia Regional Anshan Online

水.. #include <iostream> #include <cstdio> #include <string.h> #include <queue> #include <vector> #include <algorithm> #include <set> using namespace std; #define N 100 double a[N]; bool cmp(double x, double y){ re

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,

HDU 5014 Number Sequence 贪心 2014 ACM/ICPC Asia Regional Xi&#39;an Online

尽可能凑2^x-1 #include <cstdio> #include <cstring> const int N = 100005; int a[N], p[N]; int init(int x) { int cnt = 0; while(x > 1) { x /= 2; cnt ++; } return cnt + 1; } int main() { int n; while(~scanf("%d", &n)){ for(int i = 0;

HDU 5010 Get the Nut(2014 ACM/ICPC Asia Regional Xi&#39;an Online)

思路:广搜, 因为空格加上动物最多只有32个那么对这32个进行编号,就能可以用一个数字来表示状态了,因为只有 ‘P’   'S' 'M' '.' 那么就可以用4进制刚好可以用64位表示. 接下去每次就是模拟了. 注意:  ‘S’ 不是只有一个. 一个东西如果不是'P'在动的话要先判断周围有没有‘P’,有的话要先吃掉      'P'在动的时候如果一个位置周围有多个东西,都要吃掉. #include<iostream> #include<cstdio> #include<alg

HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)

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

poj 5001 Walk &amp;&amp;2014 ACM/ICPC Asia Regional Anshan Online 1005(dp)

http://acm.hdu.edu.cn/showproblem.php?pid=5001 思路:dp计算出途径每个点的总概率,1-x即为所求解. dp题,先介绍下dp[i][j]为第j步走在第i个点的概率,那么dp[i][j]=dp[x1][j-1]+dp[x2][j-1]+...,x1,x2为i 的相邻节点.上一步在相邻节点这一步才能走到该点嘛. 每个点概率要一个一个的算,当算到第ii个点时(没打错,ii个点与代码对应),从起点推起,起点嘛,算是第0步吧,每个点被选中几率1.0/n,直接计

HDU 4998 Rotate 计算几何 2014 ACM/ICPC Asia Regional Anshan Online

题意: 有一个平面放在一个二维坐标轴上 给定n个操作 (x,y) p 表示把平面绕着(x,y) 逆时针转p弧度. 最后的结果相当于平面绕着(X, Y) 逆时针旋转了P弧度. 求:X,Y,P 思路: 任取一个三角形ABC,然后根据n个操作得到A'B'C', 然后求外心. 旋转的角度就是相加..==为啥我也不大清楚,不是本弱写的. #include <cstdio> #include <algorithm> #include <iostream> #include <

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 is associated with an integer as the weight. Your task is to deal with M operations of 4 types: 1.Delete an edge (x, y) from the tree, and then add a