POj 2159 Dividing
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 71453 | Accepted: 18631 |
Description
Input
The last line of the input file will be "0 0 0 0 0 0"; do not process this line.
Output
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. 一件物品有a[i]件,总价值为i*a[i],为能否平分,多重背包问题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll dp[];
ll a[],b;
ll ans,pos,n,m;
int main()
{
int count=;
while(scanf("%d",&a[]))
{
ans=a[];
mem(dp);
dp[]=;
for(int i=;i<=;i++)
{
scanf("%d",&a[i]);
ans+=i*a[i];
}
if(!ans) break;
printf("Collection #%d:\n",count++);
if(ans%)
{
printf("Can't be divided.\n\n");
continue;
}
pos=ans/;
for(int i=;i<=;i++)
{
if(!a[i]) continue;
for(int t=;a[i];t*=)
{
if(a[i]<t) t=a[i];
for(int k=pos;k>=t*i;k--)
{
if(dp[k-t*i]) dp[k]=;
}
a[i]-=t;
}
}
if(dp[pos]) printf("Can be divided.\n\n");
else printf("Can't be divided.\n\n");
}
return ;
}
POj 2159 Dividing的更多相关文章
- POJ 2373 Dividing the Path(DP + 单调队列)
POJ 2373 Dividing the Path 描述 农夫约翰的牛发现,在他的田里沿着山脊生长的三叶草是特别好的.为了给三叶草浇水,农夫约翰在山脊上安装了喷水器. 为了使安装更容易,每个喷头必须 ...
- POJ 2159 Ancient Cipher 难度:0
题目链接:http://poj.org/problem?id=2159 #include <cstring> #include <cstdio> #include <cc ...
- Poj 2159 / OpenJudge 2159 Ancient Cipher
1.链接地址: http://poj.org/problem?id=2159 http://bailian.openjudge.cn/practice/2159 2.题目: Ancient Ciphe ...
- POJ 1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- poj 2373 Dividing the Path
Dividing the Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2858 Accepted: 1064 ...
- POJ 1014 Dividing 多重背包
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63980 Accepted: 16591 Descri ...
- POJ 1014 Dividing(多重背包+二进制优化)
http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...
- DFS(DP)---POJ 1014(Dividing)
原题目:http://poj.org/problem?id=1014 题目大意: 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两 ...
随机推荐
- js实现图片上传后即时预览
//关于FileReader对象 http://blog.csdn.net/zk437092645/article/details/8745647 <!DOCTYPE html> < ...
- 为什么使用Nginx & Nginx的使用
Nginx在Windows平台的配置: 什么是Nginx? 根据前面的对比,我们可以了解到Nginx是一个http服务器.是一个使用c语言开发的高性能的http服务器及反向代理服务器.Nginx是一款 ...
- 使用let's encrypt为你的Ubuntu14+nginx网站保驾护航!
finch最近正在研究一个新的网站系统,闲的没事想搞搞ssl,结果搞了两天,遇到很多问题,现在记录并分享一下经验. 环境之前搭建好了是Ubuntu14+nginx+php5+mysql 现在开始使用l ...
- NET Core微服务之路:实战SkyWalking+Exceptionless体验生产下追踪系统
原文:NET Core微服务之路:实战SkyWalking+Exceptionless体验生产下追踪系统 前言 当一个APM或一个日志中心实际部署在生产环境中时,是有点力不从心的. 比如如下场景分析的 ...
- BZOJ——T 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛
http://www.lydsy.com/JudgeOnline/problem.php?id=1612 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1 ...
- SpringMVC拓展
### 原生SpringMVC有如下缺陷 参数的JSON反序列化只支持@RequestBody注解,这意味着不能在controller方法中写多个参数,如下代码是不对的 public Map test ...
- Effective JavaScript Item 40 避免继承标准类型
本系列作为Effective JavaScript的读书笔记. ECMAScript标准库不大.可是提供了一些重要的类型如Array,Function和Date.在一些场合下.你或许会考虑继承当中的某 ...
- vim 基础学习之文件跳转
1. ''-当前文件上次跳转之前的位置2. '.-当前文件上次修改的位置,只要是发生了可能导致变化的命令操作就会被标记,哪怕实际结果没有变化3. '^-当前文件上次插入的位置,只要是发生了插入操作命令 ...
- Linux 内核源码(kernel source)
查看内核的发行版:uname -r(--kernel-release) $ uname -r 4.4.0-78-generic 内核源码所在的位置:/usr/src $ cd /usr/src $ l ...
- CentOS7 启动[root@localhost ~]# systemctl start docker Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for de
1).在linux虚拟机上安装docker步骤:1.检查内核版本,必须是3.10及以上uname ‐r2.安装dockeryum install docker3.输入y确认安装4.启动docker[r ...