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 获得这样一个降序的数组: ...
随机推荐
- 百度语音合成 composer
https://packagist.org/packages/jormin/baidu-speech http://ai.baidu.com/docs#/TTS-Online-PHP-SDK/top
- unity脚本封装成dll
先申明一下这样做是有需要的.当我们需要把脚本提供给第三方使用,而又不希望对方看到具体的实现过程,这时候就需要将代码封装编译成dll文件,供第三方调用.或是多个项目都要用到同一个模块或同样的功能,则可以 ...
- P1783 二分并查集写法
并查集 + 二分 我是 并查集 + 二分 做的QVQ 思路:两两枚举点之间的距离,sort排序,使距离有序.二分答案,每次判断是否符合条件,然后缩小查询范围,直到满足题目要求(保留2位小数精度就为 0 ...
- Git之简介及安装
简介 Git是一个分布式版本控制系统,GitHub相当于一个远程仓库,注册账号可免费获得Git远程仓库. GitHub使用参考:https://guides.github.com/activities ...
- JedisCluster实践
1. Spring中运用JedisCluster http://blog.csdn.net/u010739551/article/details/52438101[spring集成 JedisClus ...
- xpack文件打包解包代码库
Github ###概述 xpack是一个文件资源打包工具及类库,可以对多文件进行打包解包. 其使用文件名的hash作为索引,建立hash索引表以加速文件查找. ###特性 支持hashid自动解冲突 ...
- BZOJ4816 数字表格
4816: [Sdoi2017]数字表格 Time Limit: 50 Sec Memory Limit: 128 MB Description Doris刚刚学习了fibonacci数列.用f[i ...
- 编程语言BrainkFuck
BrainFuck由Urban Müller在1993年创建,是经常被吐槽的语言,不过我觉得除了名字其它都还挺正常的,没错我觉得这个语言设计的很正常没有Fuck到我的脑子,大概是因为我根本就没有脑子吧 ...
- 27、增强for循环
增强for循环 使用增强for循环可以简化数组和Collection集合的遍历,格式: for(元素数据类型 变量 : 数组或者Collection集合) { 使用变量即可,该变量就是元素 } 例: ...
- PHP编程效率的20个要点-[转]
用 单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则 不会,注意:只有echo能这么做,它是一种可以把多个字符 串当作参数的“函数”(译注:PHP手 ...