输入n,代表学院里面有n种设备,并且在下面输入n行,每一行输入v,m代表设备的价格为v,设备的数量是m.然后要求把这些设备的总价值分摊,尽量平分,使其总价值接近相等,最好是相等 比如样例二(1+X10)(1+X20+X40)(1+X30)展开后 从sum的一半开始向下枚举 找到第一有系数的X Sample Input210 120 1310 1 20 230 1-1 Sample Output20 1040 40 # include <iostream> # include <cstdi…
链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用母函数的思想解,只是求的不是方案数,而是推断尽可能接近总价值的一半的方案是否存在. 也能够用背包思想,每种物品的价值和数量已知,能够将总价值的一半作为容量,求最大价值,也就最接近所求值了 注:数组要开的略微大一点,否则可能WA #include<stdio.h> #include<strin…
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #incl…
有num1个 1 ,num2个 2 ,num3个 5问它们不能组成的最小正整数是谁 样例的母函数 (1+X)(1+X2)(1+X5+X10+X15)展开后 X4的系数为0 Sample Input1 1 30 0 0 Sample Output4 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <string>…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 问题描述 Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you…
完数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22289    Accepted Submission(s): 8150 Problem Description 完数的定义:如果一个大于1的正整数的所有因子之和等于它的本身,则称这个数是完数,比如6,28都是完数:6=1+2+3:28=1+2+4+7+14. 本题的任务是判断两个正…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出每个物体的价值和物体的数量,如何分使得A,B所得价值最接近并且A的价值不能小于B 思路:将总和平分后,就是一道01背包题了 #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int maxn = 1e6; int val[maxn];…
http://acm.hdu.edu.cn/showproblem.php?pid=1171 基础的01背包,求出总值sum,背包体积即为sum/2 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ],bao[]; int main() { int sum,i,j,k,m,n,a; while(scanf("%d",&n)!=EOF)…
http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出一系列的价值,需要平分,并且尽量接近. 思路:0—1背包问题. 0-1背包问题也就是有n种物品且每种只有一个.第i个物品的体积为vi,重量为wi.选择一些物品装到背包中,使得体积不超过背包的前提下重量尽可能大. 用f(i,j)表示“把前i个物品装到容量为j的背包中的最大总重量,其状态转移方程就是: f(i,j)=max{ f(i-1,j),f(i-1,j-v[i])+w[i] } 所以在第i个…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 分析: 例如数据 3 10    2 20    1 30    1 获得这样一个降序的数组:30 20 10 10 (两个10是因为10值物品有两个) 总物品价值的一半为背包容量,然后从价值大的物品开始选,当当前背包中物品价值加上将要放的物品的价值大于背包容量的时候,将要放入背包的物品不放入 注意点 1.n为负数的时候停止循环,而不是n==-1 2.背包容量为有小数的数时,取ceil上极限…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27961    Accepted Submission(s): 9847 Problem Description Nowadays, we all know that Computer College is the biggest department…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028 就是可以用任意个1.2.3....,所以式子写出来就是这样:(1+x+x^2+...)(1+x^2+x^4+...)(1+x^3+x^6+...)...(1+x^n+x^(2*n)+...)... 因为求 x^n 系数,所以再往后的式子就没有贡献了,求到第 n 个式子即可. 一个x^2就像一条边一样,可以让第 k 项的系数转移给第 k+2 项.按这个思路写代码就行了. #include<iostr…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28020    Accepted Submission(s): 9864 Problem Description Nowadays, we all know that Computer College is the biggest department…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24002    Accepted Submission(s): 8458 Problem Description Nowadays, we all know that Computer College is the biggest department…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29234    Accepted Submission(s): 10275 Problem Description Nowadays, we all know that Computer College is the biggest department…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32578    Accepted Submission(s): 11377 Problem Description Nowadays, we all know that Computer College is the biggest department…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19108    Accepted Submission(s): 6707 Problem Description Nowadays, we all know that Computer College is the biggest department…
Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.The splitting is absolutely a big…
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 40976 Accepted Submission(s): 14090 Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe yo…
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28468    Accepted Submission(s): 10023 Problem Description Nowadays, we all know that Computer…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51519    Accepted Submission(s): 17609 Problem Description Nowadays, we all know that Computer College is the biggest department…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 48364 Accepted Submission(s): 16581 Problem Description Nowadays, we all know that Computer College is the biggest department in H…
B - Big Event in HDU Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002. The splitting is absolutely a b…
Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.The splitting is absolutely a big…
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002. The splitting i…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 51181    Accepted Submission(s): 17486 Problem DescriptionNowadays, we all know that Computer College is the biggest department…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57986    Accepted Submission(s): 19484   Problem Description Nowadays, we all know that Computer College is the biggest departme…
Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.The splitting is absolutely a big…
题意:给n种房子,每种房子有一个值val和个数cnt,现在要把这些房子分成两部分,争取两部分总值相等,如果不能相等,让A>B,且A-B最小. 解法:先跑一次生成函数,c[n]表示组成总值为n的方法种数,然后从Total/2~0枚举B的总值,如果c[i]不为0,说明可以达到 i 这个状态,说明这就是B的最接近A的值(因为最接近Total/2).算法复杂度较高.跑了1600多ms,不知道还有没有更优的算法. 代码: #include <iostream> #include <cstdi…
求能装入大小为sum/2的背包的最大价值 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <sstream> #include <string> #…