HDU 1171 背包】的更多相关文章

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28020    Accepted Submission(s): 9864 Problem Description Nowadays, we all know that Computer College is the biggest department…
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…
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #incl…
链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用母函数的思想解,只是求的不是方案数,而是推断尽可能接近总价值的一半的方案是否存在. 也能够用背包思想,每种物品的价值和数量已知,能够将总价值的一半作为容量,求最大价值,也就最接近所求值了 注:数组要开的略微大一点,否则可能WA #include<stdio.h> #include<strin…
题目链接: 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…
1171 题意比较简单,这道题比较特别的地方是01背包中,每个物体有一个价值有一个重量,比较价值最大,重量受限,这道题是价值受限情况下最大,也就值把01背包中的重量也改成价值. //Problem : 1171 ( Big Event in HDU ) Judge Status : Accepted #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> us…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. 思路:01背包. 先把商品的总价值计算出来,sum/2做为背包的容量. 然后讲同种商品的多件,存储为不同商品 同样价值的形式,也就是我们用一个一维数组来存储,不用一个二维或是两个一维数组来存. 感想:好久没有做背包的题目了,今天来做,忘了好多思路,这提醒着我,学习不能一直都在学新东西,也要及时的复习.…
http://acm.hdu.edu.cn/showproblem.php?pid=1171 基础的01背包,求出总值sum,背包体积即为sum/2 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ],bao[]; int main() { int sum,i,j,k,m,n,a; while(scanf("%d",&n)!=EOF)…
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个…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32578    Accepted Submission(s): 11377 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…
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…
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…
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): 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…
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): 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…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29234    Accepted Submission(s): 10275 Problem Description Nowadays, we all know that Computer College is the biggest department…
题目链接:hdu1171 思路:将多重背包转为成完全背包和01背包问题,转化为01背包是用二进制思想,即件数amount用分解成若干个件数的集合,这里面数字可以组合成任意小于等于amount的件数 比如:7的二进制 7 = 111 它可以分解成 001 010 100 这三个数可以组合成任意小于等于7 的数,而且每种组合都会得到不同的数: 如果13 = 1101 则分解为 0001 0010 0100 0110 前三个数字可以组合成7以内任意一个数,加上 0110 = 6 可以组合成任意一个大于…
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…
题目链接 题意:给出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…
题意:给出价值和数量,求能分开的最近的两个总价值,例如10,20*2,30,分开就是40,40 链接:点我 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 100000…
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 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…
题意:给出n个物品的价值和数目,将这一堆物品分给A,B,问怎样分使得两者的价值最接近,且A的要多于B 第一次做的时候,没有思路---@_@ 因为需要A,B两者最后的价值尽可能接近,那么就可以将背包的容量转化为sum/2来做,然后按照01背包的做法来做 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 500005 using names…
题意: 杭电搬迁,有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){…
代码: #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;…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出每个物体的价值和物体的数量,如何分使得A,B所得价值最接近并且A的价值不能小于B 思路:将总和平分后,就是一道01背包题了 #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int maxn = 1e6; int val[maxn];…