输入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 ……. (母函数)的更多相关文章

  1. hdu 1171 Big Event in HDU(母函数)

    链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用 ...

  2. HDU 1171 Big Event in HDU(01背包)

    题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...

  3. 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 ...

  4. 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 ...

  5. 居然因为交换错了好几把。。。。,还有坑点是num1可以大于num2

    完数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  6. Big Event in HDU HDU - 1171

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出每个物体的价值和物体的数量,如何分使得A,B所得价值最接近并且A的价值不能小于B 思路 ...

  7. HDU 1171 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 基础的01背包,求出总值sum,背包体积即为sum/2 #include<stdio.h> # ...

  8. HDU 1171 Big Event in HDU(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出一系列的价值,需要平分,并且尽量接近. 思路:0—1背包问题. 0-1背包问题也就是有n种物品且 ...

  9. HDU 1171 (01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 分析: 例如数据 3 10    2 20    1 30    1 获得这样一个降序的数组: ...

随机推荐

  1. 逻辑回归原理_挑战者飞船事故和乳腺癌案例_Python和R_信用评分卡(AAA推荐)

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...

  2. python中__init__()、__new__()、__call__()、__del__()用法

    关于__new__()的用法参考: http://www.myhack58.com/Article/68/2014/48183.htm 正文: 一.__new__()的用法: __new__()是在新 ...

  3. koa中间件机制

    Koa是Express原班人马打造的一个更小,基于nodejs平台的下一代web开发框架. koa2利用的是async/await,洋葱圈模型. 1. koa2中间件基本用法

  4. 【c#】腾讯人脸识别api签名

    using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...

  5. 自定义模板类型vs模板类型自动推测

    [自定义模板类型vs模板类型自动推测] GCC在编译时,先确定看是否人工定义了模板的类型,如果定义了,则看传递的参数是否能转换成定义后的类型,如果没定义,则根据参数确定定义的类型. 1. 是否人工定义 ...

  6. 51、多线程创建的三种方式之实现Callable接口

    实现Callable接口创建线程 Callable接口是在jdk5版本中加入的,这个接口在java.util.concurrent包下面,与其他两种方式不同的地方在于使用Callable接口创建的线程 ...

  7. Python练习-一个简单的生成器

    今天我们学习了生成器,怎么理解生成器呢,其实就是使用函数的方式自己建立一个迭代器 # 编辑者:闫龙 #做一个简单的生成器 def EasyGene(*args): #建立一个生成器方法并传递多个参数 ...

  8. Linux基础操作-分区概念

    开启Linux系统前添加一块大小为20G的SCSI硬盘 开启系统,右击桌面,打开终端 为新加的硬盘分区,一个主分区大小为10G,剩余空间给扩展分区,在扩展分区上划分两个逻辑分区,大小各5G 进入分区工 ...

  9. Mysql查看建表语句以及修改引擎

    更多内容推荐微信公众号,欢迎关注: 1 查看系统支持的存储引擎 show engines; 2 查看表使用的存储引擎 两种方法: a.show table status from db_name wh ...

  10. php魔术函数 __clone()

    原文地址: http://www.nowamagic.net/librarys/posts/php/32 PHP4面向对象功能一个很大的缺点,是将对象视为另一种数据类型,这使得很多常见的OOP方法无法 ...