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;

int t, n, dp[N], T[N];

int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			scanf("%d", &T[i]);
			sum += T[i];
		}
		sum /= 2;
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		for (int i = 1; i <= n; i++) {
			for (int k = sum; k >= 0; k--) {
				for (int j = 1; j <= T[i]; j++) {
					if (k - j < 0) break;
					dp[k] = (dp[k] + dp[k - j]) % MOD;
				}
			}
		}
		printf("%d\n", dp[sum]);
	}
	return 0;
}
时间: 2024-08-02 06:55:33

HDU 5000 Clone(鞍山网络赛D题)的相关文章

HDU-5000 Clone 鞍山网络赛D题 DP+猜想

一个人可以克隆出自己克隆体,一个克隆体有n个方面,如果一个克隆体全方面逊色于另外一个克隆体,那么它就无法存活下去,问怎样可以同时最多存活的克隆体数目.思路:得到最大值的时候,每个克隆体的属性之和必然是相同的,并且这个和是所有方面最高属性和的二分之一.问题就变成n个数组成sum/2的方案数. #include <iostream> #include <cstdio> #include <cmath> #include <queue> #include <

HDU 5006 Resistance(鞍山网络赛J题)

HDU 5006 Resistance 思路:这题由于数据是随机的..电阻不是1就是0,就可以先缩点,把电阻为0的那些边缩掉,只考虑有电阻的边,这样的话缩下来点数就不多了,就可以利用高斯消元+基尔霍夫定律去搞了 代码: #include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <algorithm> using namespace std; c

HDU 5003 Osu!(鞍山网络赛G题)

HDU 5003 Osu! 题目链接 就一签到题,排序之后for一遍计算出答案即可 代码: #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <algorithm> #include <cmat

HDU 5001 Walk(鞍山网络赛E题)

HDU 5001 Walk 题目链接 思路:枚举每个要经过的点,然后进行状态转移,状态为dp[i][j],状态表示当前在j的点,已经走了i步,每次转移的时候,不从这个枚举的点出发,这样就可以求出所有路径经过该点的概率p, 然后1 - p就是不经过的答案 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; con

HDU 6205 2017沈阳网络赛 思维题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b[i]张)翻上,然后下一堆继续,直到没有足够的牌翻上,然后你可以获得当前已经操作过的堆的所有牌.最初你可以调整堆的顺序,把第一堆放到最后一堆(逆时针旋转),你可以重复这个操作,问你要重复多少次这个操作,才能获得最多的牌. 解法:先把这个序列复制一遍放在原来的序列后面.当i=n的时候结束就可以了,每次

hdu 5078 2014鞍山现场赛 水题

http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,因为说了ti<ti+1 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include &l

hdu 5078(2014鞍山现场赛 I题)

数据 表示每次到达某个位置的坐标和时间 计算出每对相邻点之间转移的速度(两点间距离距离/相隔时间) 输出最大值 Sample Input252 1 9//t x y3 7 25 9 06 6 37 6 01011 35 6723 2 2929 58 2230 67 6936 56 9362 42 1167 73 2968 19 2172 37 8482 24 98 Sample Output9.219544457354.5893762558 1 # include <iostream> 2 #

hdu 5446(2015长春网络赛J题 Lucas定理+中国剩余定理)

题意:M=p1*p2*...pk:求C(n,m)%M,pi小于10^5,n,m,M都是小于10^18. pi为质数 M不一定是质数 所以只能用Lucas定理求k次 C(n,m)%Pi最后会得到一个同余方程组x≡B[0](mod p[0])x≡B[1](mod p[1])x≡B[2](mod p[2])......解这个同余方程组 用中国剩余定理 Sample Input19 5 23 5 Sample Output6 1 # include <iostream> 2 # include <

HDU-5001 Walk 2014年鞍山网络赛E题

依次枚举每个不能走过的点,DP递推下一步情况,求出所有其他点的概率之和即为这个点不会被走过的概率. #include <iostream> #include <cstdio> #include <queue> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <iomanip> #include