套模板+填参数=AC

POJ还是用C++提交靠谱

Dividing
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 51256 Accepted: 12981

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 just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value. Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.

Input

Each line in the input file describes one collection of marbles to be divided. The lines contain six non-negative integers n1 , . . . , n6 , where ni is the number of marbles of value i. So, the example from above would be described by the input-line "1 0 1 2 0 0". The maximum total number of marbles will be 20000. 
The last line of the input file will be "0 0 0 0 0 0"; do not process this line.

Output

For each collection, output "Collection #k:", where k is the number of the test case, and then either "Can be divided." or "Can't be divided.". 
Output a blank line after each test case.

Sample Input

1 0 1 2 0 0 1 0 0 0 1 1 0 0 0 0 0 0

Sample Output

Collection #1:Can't be divided.Collection #2:Can be divided.

Source

Mid-Central European Regional Contest 1999

#include <iostream>

#include <cstring>
using namespace std;
int v;
int dp[333333];//RE了就加个3
void zpack(int* a,int c,int w)
{
for(int i=v;i>=c;i--)
a=max(a,a[i-c]+w);
}
void cpack(int* a,int c,int w)
{
for(int i=c;i<=v;i++)
a=max(a,a[i-c]+w);
}
void multipack(int* a,int c,int w,int m)
{
if(c*m>=v)
{
cpack(a,c,w);
return ;
}
int k=1;
while(k<m)
{
zpack(a,c*k,w*k);
m-=k;
k*=2;
}
zpack(a,c*m,w*m);
}
int main()
{
int cur=0;
while(true)
{
int a[8];
memset(a,0,sizeof(a));
memset(dp,0,sizeof(dp));
int sum=0;
for(int i=1;i<=6;i++)
{
cin>>a;
sum+=a*i;
}
v=sum/2;
if(sum==0) break;
for(int i=1;i<=6;i++)
multipack(dp,i,i,a);
cout<<"Collection #"<<++cur<<":\n";
if(sum-dp[v]==dp[v])
cout<<"Can be divided."<<endl<<endl;
else
cout<<"Can't be divided."<<endl<<endl;
}
return 0;
}

转载于:https://www.cnblogs.com/CKboss/archive/2013/05/28/3351054.html

POJ 1014 Dividing相关推荐

  1. POJ 1014: Dividing

    写在前面: 本题非常有意思, 因此我在编程前后和撰写本文前, 在网上查询并阅读了大量关于本题的解题报告. 当中有两种似是而非但提交后却可以 AC 的解法引起了我的兴趣, 一是原作者宣称的 " ...

  2. POJ 1014 Dividing(多重背包 + 倍增优化)

    题意: 求一种划分方案使结果最公平. 思路: 多重背包,然后把物品分为 2^0, 2^1, ... , 2^k,... 等. #include <iostream> #include &l ...

  3. POJ 1014 Dividing 背包

    二进制优化,事实上是物体的分解问题. 就是比方一个物体有数量限制,比方是13,那么就须要把这个物体分解为1. 2, 4, 6 假设这个物体有数量为25,那么就分解为1, 2, 4. 8. 10 看出规 ...

  4. POJ 1014 Dividing【多重背包+二进制优化】

    大意: 价值1, 2, 3, --, 6的物品分别a1, a2, --, a5, a6件 问能否把这些物品分成两份,使其具有相同的价值(所有物品必须全部用上) 分析: 给个物品有多件,即多重背包 只要 ...

  5. [poj 1014]Dividing的DFS解法解读和DP解法

    转载来源: http://blog.csdn.net/lyy289065406/article/details/6661449 这道题比较特殊,用DFS也是对的,而且可以进行优化,即使直接n[i]-- ...

  6. 【POJ】 1014 Dividing(多重背包,优化)

    [POJ] 1014 Dividing(多重背包,优化) [题目链接]http://poj.org/problem?id=1014 题目 Description Marsha and Bill own ...

  7. 多重背包 (poj 1014)

    题目:Dividing 题意:6种重量的的石头,每个给定数量,用总重的一半去装,问能否装满. #include <iostream> #include <algorithm> ...

  8. POJ 2373 Dividing the Path(灌溉草场)

    描述 在一片草场上:有一条长度为L (1 <= L <= 1,000,000, L为偶数)的线段. John的N (1 <= N <= 1000) 头奶牛都沿着草场上这条线段吃 ...

  9. 背包问题的二进制优化

    01背包问题 图解+详细解析 (转载) 01背包问题 图解+详细解析 (转载)_迪迦 • 奥特曼-CSDN博客 01背包问题 图解+详细解析 (转载)_可控的事情要谨慎,不可控的事情要乐观.-CSDN ...

最新文章

  1. git查看各个branch之间的关系图
  2. 2012组策略自动部署wsus
  3. Java基础:异常机制
  4. android 代码混淆示例
  5. SAP ABAP Debug 小技巧
  6. beyond compare 不自动比较解决办法(没解决,可以ctrl + F5手动比较)
  7. BZOJ 1800 [Ahoi2009]fly 飞行棋
  8. 工作106:crul哈哈概念
  9. 力扣 1553. 吃掉 N 个橘子的最少天数 记忆化DFS|记忆化BFS|剪枝
  10. Thinkphp开发时关闭缓存的方法
  11. AndroidStudio_Gradle介绍以及在androidstudio中的使用---Android原生开发工作笔记76
  12. Python学习教程:Python自动化测试框架需要学习哪些?
  13. 2022新版UI云购H5系统源码+完美运行/功能强大
  14. flex builder
  15. 面向对象的系统分析(一)-系统分析方法
  16. python世界杯问题
  17. 世界银行公布各国1996-2018年GDP及GDP增长率
  18. 微信小程序之字体样式设置
  19. 无需注册,直接在网页拨打免费电话
  20. 英语发音规则---I字母常见发音组合有哪些

热门文章

  1. tomcat基本使用(二)
  2. 结对-五子棋游戏-开发环境搭建过程
  3. nginx下目录浏览及其验证功能、版本隐藏等配置记录
  4. 使用命令将logcat中的内容输出到文本文件中
  5. My interested stuff(2008-07-18)
  6. 如何卸载IE7重装IE6
  7. 1090 危险品装箱 (25分)
  8. python错误异常处理try except Error
  9. python读取json文件多个json数据_Python 加载包含多个JSON对象的JSON文件
  10. rda冗余分析步骤_FEMS Microbiol Ecol |微生物生态学中的多变量分析