题目链接: 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…
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 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…
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): 19108    Accepted Submission(s): 6707 Problem Description Nowadays, we all know that Computer College is the biggest department…
链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用母函数的思想解,只是求的不是方案数,而是推断尽可能接近总价值的一半的方案是否存在. 也能够用背包思想,每种物品的价值和数量已知,能够将总价值的一半作为容量,求最大价值,也就最接近所求值了 注:数组要开的略微大一点,否则可能WA #include<stdio.h> #include<strin…
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): 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…
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #incl…
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…
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个…
题目链接 题意:给出n个物品的价值v,每个物品有m个,设总价值为sum,求a,b.a+b=sum,且a尽可能接近b,a>=b. 题解:01背包. #include <bits/stdc++.h> using namespace std; ],dp[],n,v,m; int main() { ) { memset(dp,,sizeof(dp)); ,cnt=; ;i<n;i++) { scanf("%d%d",&v,&m); sum+=v*m; w…
题意:给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…
题目链接:hdu1171 思路:将多重背包转为成完全背包和01背包问题,转化为01背包是用二进制思想,即件数amount用分解成若干个件数的集合,这里面数字可以组合成任意小于等于amount的件数 比如:7的二进制 7 = 111 它可以分解成 001 010 100 这三个数可以组合成任意小于等于7 的数,而且每种组合都会得到不同的数: 如果13 = 1101 则分解为 0001 0010 0100 0110 前三个数字可以组合成7以内任意一个数,加上 0110 = 6 可以组合成任意一个大于…
点我看题目 题意 : 给你一个n,然后n组数据,每组两个数字,一个是物品的价值,另外一个是物品的数量,让你尽量将这些东西分成价值相等的两份,如果无法相等就前一份要大于后一份. 思路 :这个题可以转化成01背包的放与不放的问题,就是该题中最后一句要注意到是一个负数终结输出而非-1 ,就因为我没发现WA了8次....真是郁闷了. #include <stdio.h> #include <string.h> #include <iostream> #include <s…
题意: 分家问题,对每种家具都估个值,给出同样价值的家具有多少个,要求尽可能平分,打印的第一个数要大于等于第二个数. 思路: 可以用背包做,也可以用母函数.母函数的实现只需要注意一个点,就是每次以一种价格递增,而不是自加.每类家具有上限,就是该类家具的价值*件数.注意判断输入的结束标志是n<0. #include <bits/stdc++.h> using namespace std; ; **/], ans[**/], big; //上限是50*50*100,但一半就够了 ], m[]…
按套路列生成函数式子然后暴力乘,这样复杂度看起来非常大,但是可以动态维护最大值,这样就是O(能过)的了 仔细想想这个多项式暴力乘理解成背包dp也行? #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=300005; int n,m,a[N],b[N],v[N],w[N]; int main() { while(scanf("%d"…
题意:给出n个物品的价值和数目,将这一堆物品分给A,B,问怎样分使得两者的价值最接近,且A的要多于B 第一次做的时候,没有思路---@_@ 因为需要A,B两者最后的价值尽可能接近,那么就可以将背包的容量转化为sum/2来做,然后按照01背包的做法来做 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 500005 using names…
代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[5005]; int dp[130005]; int main() { int n; while(scanf("%d",&n)&&n>=0) { int k=1; int s=0; for(int i=0;i<n;i++) { int x,y;…
题意: 杭电搬迁,有N种设备,每种设备有个价值V,数量M,要求将这些设备平分,使得平分后两边的总价值尽可能地相等. 输出两边各自的总价值. 思路: 背包DP后,P=所有的总价值/2,然后从P开始往两边找到第一个满足的价值. 可以降维,但是要注意for循环的顺序. 看代码. 代码: int v[55], m[55]; bool dp[250005]; int main(){ int n; while(scanf("%d",&n)!=EOF && n>=0){…
HDU 3591 The trouble of Xiaoqian(多重背包+全然背包) pid=3591">http://acm.hdu.edu.cn/showproblem.php? pid=3591 题意: 有一个具有n种货币的货币系统, 每种货币的面值为val[i]. 如今小杰手上拿着num[1],num[2],-num[n]个第1种,第2种-第n种货币去买价值为T(T<=20000)的商品, 他给售货员总价值>=T的货币,然后售货员(可能,假设小杰给的钱>T,那肯…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23728    Accepted Submission(s): 8363 Problem Description Nowadays, we all know that Computer College is the biggest department…
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 is…
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): 38607    Accepted Submission(s): 13362 Problem Description Nowadays, we all know that Computer College is the biggest department…