POJ 1014 Dividing】的更多相关文章

http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include<iostream> #include<string> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; ; int sum; ]; int d[max…
原题目:http://poj.org/problem?id=1014 题目大意: 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两份的总价值相等,其中一个物品不能切开,只能分给其中的某一方,当输入六个0是(即没有物品了),这程序结束,总物品的总个数不超过20000 输出:每个测试用例占三行: 第一行: Collection #k: k为第几组测试用例 第二行:是否能分(具体形式见用例) 第三行:空白(必须注意,否则PE) 一:…
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles.…
Dividing   Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they cou…
Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63980   Accepted: 16591 Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbl…
多重背包模板- #include <stdio.h> #include <string.h> int a[7]; int f[100005]; int v, k; void ZeroOnePack(int cost, int weight) { for (int i = v; i >= cost; i--) if (f[i - cost] + weight > f[i]) f[i] = f[i - cost] + weight; } void CompletePack(…
题意 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两份的总价值相等,其中一个物品不能切开,只能分给其中的某一方,当输入六个0是(即没有物品了),这程序结束,总物品的总个数不超过20000 思路 裸的多重可行性背包,设dp[i]表示容量为i是否可装.状态设计看代码吧. 代码 [cpp] #include <iostream> #include <cstdio> #include <cmath> #in…
Q: 倍增优化后, 还是有重复的元素, 怎么办 A: 假定重复的元素比较少, 不用考虑 Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the…
二进制优化,事实上是物体的分解问题. 就是比方一个物体有数量限制,比方是13,那么就须要把这个物体分解为1. 2, 4, 6 假设这个物体有数量为25,那么就分解为1, 2, 4. 8. 10 看出规律吗,就是分成2的倍数加上位数,比方6 = 13 - 1 - 2 - 4, 10 = 25 - 1 - 2 - 4 - 8.呵呵,为什么这么分解? 由于这样分解之后就能够组合成全部1到13的数.为25的时候能够组合成全部1到25的数啦. 就是这么一个分解物体.最后组合的问题. 不明确? 给多几个数字…
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if…
这个问题是存在做.我发现即使是可行的一个问题,但不一定正确. 大部分数据疲软,因为主题. id=1014">poj 1014 Dividing 题目大意:有6堆石头,权重分别为1 2 3 4 5 6,要求输入 每堆个数 ,求能否够平分石头使得两堆价值同样. 网上对这道题的做法就两种,当中有错误的版本号.却也能够AC. 起初这让我等菜鸟感慨代码的简洁,但无法得出正确性的证明 接下来就对两种方法的错误性进行证明. 1.多重背包 #include <map> #include<…
POJ 2373 Dividing the Path 描述 农夫约翰的牛发现,在他的田里沿着山脊生长的三叶草是特别好的.为了给三叶草浇水,农夫约翰在山脊上安装了喷水器. 为了使安装更容易,每个喷头必须安装在山脊上(我们可以认为这是一条长度为L(1<=L<=1,000,000)的一维数列:L是偶数). 每个洒水器沿山脊向两个方向地面排水一段距离.每个喷雾半径是A.B范围内的整数(1<=A<=B<=1000).农夫约翰需要给整个山脊浇水,用一个喷头覆盖整个山脊上的每一个位置.此外…
Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69575   Accepted: 18138 Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbl…
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could…
多重背包模型  写的时候漏了一个等号找了半天 i<<=1 !!!!!! #include<iostream> #include<cstdio> #include<cstring> using namespace std; ]; ]; ]; int main(){ ; ; ])==){ ]; ; ;j<=a[];j<<){ m[flag++]=j; a[]-=j; } ])m[flag++]=a[]; ;i<n;i++){ scanf(…
题目链接:http://poj.org/problem?id=1014 背包问题太经典了,之前的一篇博客已经讲了背包问题的原理. 这一个题目是多重背包,但是之前的枚举是超时的,这里采用二进制优化. 这是所有01背包,完全背包,多重背包的模板哦! #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int sum;…
题目:Dividing 题意:6种重量的的石头,每个给定数量,用总重的一半去装,问能否装满. #include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <cmath> #include <cstdio> #include <string> #include <cstring> #include…
Dividing the Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2858   Accepted: 1064 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill in his field is particularly good. To keep the clo…
Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 71453   Accepted: 18631 Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbl…
大意是,从输入六个数 .第i个数代表价值为i的有几个,平均分给两个人 ,明摆着的背包问题,本来以为把他转化为01背包.可是TLe,后来发现是12万的平方还多,所以妥妥的TLE,后来发现这是一个全然背包问题.然后即纠结了 ,没学过啊 .最后发现思想好i是蛮简单的,水水的A掉了.最后注意一下初始化问题和输入问题后就好了 #include <stdio.h> #include <string.h> int a[10]; int dp[120005]; int maxx(int a,int…
#include <iostream> #include <stdio.h> #include <cstring> #define INF 100000000 using namespace std; ]; //f[j]相当于f[i][j]: 考虑1...i个物品,恰好放到容量为j,所能达到的最大价值 int v; //背包容量 void complete_pack(int *dp, int c, int w) { for(int i = c; i <= v; i…
题意:给出价值为1,2,3,4,5,6的6种物品数量,问是否能将物品分成两份,使两份的总价值相等. 思路:求出总价值除二,做多重背包,需要二进制优化. 代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n[7]; int v,sum; bool flag; int dp[100000]; /*完全背包*/ void CompletePack(int cos…
思路: 设dp[i]为覆盖i所用的最小数量,那么dp[i] = min(dp[k] + 1),其中i - 2b <= k <= i -2a,所以可以手动开一个单调递增的队列,队首元素就是k. 初始状态为dp[0] = 0,注意喷水覆盖的范围是偶数且不重叠,所以插入队列的必是偶数.有牛的地方不能作为边界,所以这些地方都要排除,可以用vis标记或者其他方法. 代码: #include<map> #include<ctime> #include<cmath> #i…
#include<iostream>#include<stdio.h>#define num 6using namespace std; bool DFS(int i,int half_sum);int a[num];int half_value;int main(){    //freopen("acm.acm","r",stdin);    int i;    int sum;    int time = 0;    while(1)  …
第一周: 经过漫长的时间,终于有时间来写一下结题报告. 地址http://acm.hust.edu.cn/vjudge/contest/view.action?cid=36180#overview A:POJ 1837       Balance      按偏移量DP                                                   题解 B:POJ 1948        Triangular Pastures   按边长DP                …
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value = acceptedNumber / avgAcceptRate + submittedNumber. 这里用到avgAcceptedRate的原因是考虑到通过的数量站的权重可能比提交的数量占更大的权重,所以给acceptedNumber乘上了一个因子. 当然计算value还有别的方法,比如POJ上…
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive…
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029, 2039, 2063, 20…
一.背包问题 最基础的一类动规问题.相似之处在于给n个物品或无穷多物品或不同种类的物品,每种物品仅仅有一个或若干个,给一个背包装入这些物品,要求在不超出背包容量的范围内,使得获得的价值或占用体积尽可能大,这一类题的动规方程f[i]一般表示剩余容量为i时取得的最大价值或最大占用体积.或者有多维状态,分别表示不同种物品的剩余量 1.Wikioi 1014 装箱问题 题目描写叙述 Description 有一个箱子容量为V(正整数,0<=V<=20000).同一时候有n个物品(0<n<=…
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 1003 Hangover792.762000 1001 Exponentiation752.486000 1006 Biorhythms705.902000 1005 I Think I Need a Houseboat686.540000 1011 Sticks647.566000 1007…