hdu 1171 有num1个w1 , num2个w2 ……. (母函数)
输入n,代表学院里面有n种设备,并且在下面输入n行,每一行输入v,m代表设备的价格为v,设备的数量是m.然后要求把这些设备的总价值分摊,尽量平分,使其总价值接近相等,最好是相等
比如样例二
(1+X10)(1+X20+X40)(1+X30)
展开后 从sum的一半开始向下枚举 找到第一有系数的X
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
Sample Output
20 10
40 40
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <list>
# define LL long long
using namespace std ; int c1[], c2[];
int w[];
int num[];
int main()
{
//freopen("in.txt","r",stdin) ;
int n;
while(scanf("%d", &n) && n>)
{
memset(w, , sizeof(w));
memset(num, , sizeof(num));
memset(c1, , sizeof(c1));
memset(c2, , sizeof(c2)); int sum = ;
for(int i = ; i <= n ; ++i)
{
scanf("%d %d", &w[i], &num[i]);
sum += w[i]*num[i];
} for(int i=; i<=w[]*num[]; i+=w[])
c1[i] = ;
int len = w[]*num[];
for(int i=; i<=n; ++i)
{
for(int j=; j<=len; ++j)
for(int k=; k<=w[i]*num[i]; k+=w[i])
{
c2[k+j] += c1[j];
}
len += w[i]*num[i];
for(int j=; j<=len; ++j)
{
c1[j] = c2[j];
c2[j] = ;
}
}
for(int i= sum/; i>=; --i)
if(c1[i] != )
{
printf("%d %d\n", sum-i, i);
break;
}
}
return ;
}
hdu 1171 有num1个w1 , num2个w2 ……. (母函数)的更多相关文章
- hdu 1171 Big Event in HDU(母函数)
链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用 ...
- HDU 1171 Big Event in HDU(01背包)
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...
- hdu 1085 有num1个 1 ,num2个 2 ,num3个 5 (母函数)
有num1个 1 ,num2个 2 ,num3个 5问它们不能组成的最小正整数是谁 样例的母函数 (1+X)(1+X2)(1+X5+X10+X15)展开后 X4的系数为0 Sample Input1 ...
- HDU 1171 Big Event in HDU 多重背包二进制优化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...
- 居然因为交换错了好几把。。。。,还有坑点是num1可以大于num2
完数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- Big Event in HDU HDU - 1171
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出每个物体的价值和物体的数量,如何分使得A,B所得价值最接近并且A的价值不能小于B 思路 ...
- HDU 1171 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=1171 基础的01背包,求出总值sum,背包体积即为sum/2 #include<stdio.h> # ...
- HDU 1171 Big Event in HDU(0-1背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出一系列的价值,需要平分,并且尽量接近. 思路:0—1背包问题. 0-1背包问题也就是有n种物品且 ...
- HDU 1171 (01背包问题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 分析: 例如数据 3 10 2 20 1 30 1 获得这样一个降序的数组: ...
随机推荐
- Qt error ------ no matching function for call to QObject::connect(QSpinBox*&, <unresolved overloaded function type>, QSlider*&, void (QAbstractSlider::*)(int))
connect(ui->spinBox_luminosity,&QSpinBox::valueChanged, ui->horizontalSlider_luminosity, & ...
- CIDR 无类别域间路由
参考百度百科 1.全称 CIDR的全称是Classless Inter-Domain Routing 2.作用 CIDR将路由集中起来,使一个IP地址代表主要骨干提供商服务的几千个IP地址,从而减轻I ...
- day8 java基础细节回顾
java之父——James Gosling java吉祥物——duke 编译: 源文件(.java文件)-->java编译器==>.class文件 运行:类装载器-->字节码校验器- ...
- Shell记录-Shell脚本基础(二)
Shell 基本运算符 算术运算符: 运算符 描述 例子 + Addition - Adds values on either side of the operator `expr $a + $b` ...
- Java中的容器类(List,Set,Map,Queue)
Java中的容器类(List,Set,Map,Queue) 一.基本概念 Java容器类类库的用途是“保存对象”,并将其划分为两个不同的概念: 1)Collection.一个独立元素的序列,这些元素都 ...
- [整理]前端模块化开发AMD CMD
前端模块化开发的价值 AMD (中文版) CMD 模块定义规范 标准构建 http://seajs.org http://chaoskeh.com/blog/why-seajs.html http:/ ...
- Python练习-一个简单的生成器
今天我们学习了生成器,怎么理解生成器呢,其实就是使用函数的方式自己建立一个迭代器 # 编辑者:闫龙 #做一个简单的生成器 def EasyGene(*args): #建立一个生成器方法并传递多个参数 ...
- sparse coding
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- [转]closed-form solution (闭合解/解析解)和数值解的理解
参考整理自:http://hi.baidu.com/cjb366/item/7290773b2d2eb9f2a9842873 closed-form solution :一般翻译为闭合解/解析解.这一 ...
- Shell-输入密码转换为*
Code: read -p "请输入使用者都名称:" USER echo -e "请输入使用者密码: \c" while : ;do char=` #这里是反引 ...