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 获得这样一个降序的数组: ...
随机推荐
- extract_by_one 根据二维数组中某字段来提取数组信息,查看有无重复信息
public function tt(){ $param = array( array ( 'hykno' => '2222222-CB', 'tcdk_fid' => '458B6D70 ...
- 《编程快速上手》--web抓取--利用webbrowser模块的mapIT.py
1.代码如下 #! python3 # mapIT.py - Launches a map in the browser using an address from the # command lin ...
- python中几种常用的数据类型
1.字典 字典的创建: dict1=dict((('name','PIG'),)),其中第一层()代表里面的内容是dict函数的输入参数.第二层和第三层代表字典中的各元素,也就是key和value组合 ...
- Xcode关闭警告
对于关闭某个警告,如果需要全局关闭的话,直接在Other C Flags里写 -Wno-...就行了,比如 -Wextra -Wno-sign-compare 就是一个常见的组合.如果相对某几个文件开 ...
- SecureCRT无法使用root正常连接Ubuntu 14.0.4.1的解决办法
问题描述 通过VirtualBox重新安装了Ubuntu 14.0.4.1 虚拟服务器,在SercureCRT中使用root帐号连接Ubuntu14.0.4.1的时候,提示“Password Auth ...
- [转载]mysql下载安装
转自https://www.cnblogs.com/tyhj-zxp/p/6693046.html 下载 打开:https://www.mysql.com/downloads/ 1.点击该项:
- 华为mate 10 pro安装失败,提示没有未包含任何证书
原因: Android 7.0 引入一项新的应用签名方案 APK Signature Scheme v2,它能提供更快的应用安装时间和更多针对未授权 APK 文件更改的保护.在默认情况下,Androi ...
- python 操作excel格式化及outlook正文,发送邮件
import requests import time import os import arrow import pandas as pd import pandas.io.formats.exce ...
- 视差插件parallarx
github上的demo,自己拿来改了改. <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
- 美轮美奂!9款设计独特的jQuery/CSS3全新应用插件(下拉菜单、动画、图表、导航等)
今天要为大家分享9款设计非常独特的jQuery/CSS3全新应用插件,插件包含菜单.jQuery焦点图.jQuery表单.jQuery图片特效等.下面大家一起来看看吧. 1.jQuery水晶样式下拉导 ...