Dividing--hdu1059(动态规划)
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.
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
Output a blank line after each test case.
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<stdlib.h> using namespace std; #define INF 0xfffffff
#define N 20
int flag,mid,a[N]; void Find(int ans,int s)
{
if(flag)
return;
if(ans==mid)
{
flag=;
return;
}
for(int i=s; i>=; i--)
{
if(a[i])
{
if(ans+i<=mid)
{
a[i]--;
Find(ans+i,i);
if(flag)
break;
}
}
}
return;
} int main()
{
int t=;
while()
{
int sum=;
for(int i=; i<=; i++)
{
scanf("%d",&a[i]);
sum+=a[i]*i;
}
if(sum==)
break;
printf("Collection #%d:\n",t++);
if(sum%==)
{
printf("Can't be divided.\n\n");
continue;
}
flag=;
mid=sum/;
Find(,);
if(flag==)
printf("Can be divided.\n\n");
else
printf("Can't be divided.\n\n");
}
return ;
}
Dividing--hdu1059(动态规划)的更多相关文章
- 动态规划--模板--hdu 1059 Dividing
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 【二进制拆分多重背包】【HDU1059】【Dividing】
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu1059 Dividing ——多重背包
link:http://acm.hdu.edu.cn/showproblem.php?pid=1059 最简单的那种 #include <iostream> #include <cs ...
- poj1014 hdu1059 Dividing 多重背包
有价值为1~6的宝物各num[i]个,求能否分成价值相等的两部分. #include <iostream> #include <cstring> #include <st ...
- hdu1059&poj1014 Dividing (dp,多重背包的二分优化)
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- 转载:hdu 动态规划题集
1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数): ...
- hdu 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】(转)
HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包 ...
- [NOIP复习]第三章:动态规划
一.背包问题 最基础的一类动规问题.相似之处在于给n个物品或无穷多物品或不同种类的物品,每种物品仅仅有一个或若干个,给一个背包装入这些物品,要求在不超出背包容量的范围内,使得获得的价值或占用体积尽可能 ...
- 【BZOJ3872】Ant colony(二分,动态规划)
[BZOJ3872]Ant colony(二分,动态规划) 题面 又是权限题... Description There is an entrance to the ant hill in every ...
- 【转载】 HDU 动态规划46题【只提供思路与状态转移方程】
1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数) ...
随机推荐
- 磁盘格式化mke2fs
-b 设置每个块的大小,当前支持1024,2048,40963种字节 -i 给一个inode多少容量 -c 检查磁盘错误,仅执行一次-c时候,会进行快速读取测试:-c -c会测试读写,会很慢 -L 后 ...
- 安装mysql时 make 时 提示 redeclaration of C++ built-in type ‘bool’ 错误
安装mysql时 make 时 提示 redeclaration of C++ built-in type ‘bool’ 错误 由于gcc-c++是在./configure后进行编译的 重新./con ...
- SpringMvc之参数绑定注解详解
引言: 前段时间项目中用到了REST风格来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为application/j ...
- HDU 5391 Zball in Tina Town (打表,水)
题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...
- DROP DOMAIN - 删除一个用户定义的域
SYNOPSIS DROP DOMAIN name [, ...] [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP DOMAIN 将从系统表中删除一个用户域. 只 ...
- Bug的分类和管理流程
1.按照严重程度划分 定义:是指Bug对软件质量的破坏程度,即BUG的存在将对软件的功能和性能产生怎样的影响 分类:系统崩溃.严重.一般.次要.建议 2.按优先级划分 定义:表示处理和修正软件缺陷的现 ...
- HTML 5 <a> 标签
href 属性 定义和用法 href 属性规定链接的目标地址. 如果未使用 href 属性,则 <a> 标签不是链接,而是链接的占位符. HTML 4.01 与 HTML 5 之间的差异 ...
- Sql Server 中锁的概念(2)
1.一般大家都对事务的四种隔离模式比较熟悉,从松到严依次是: - 读取未提交(Read uncommitted):处于此模式下可能会出现脏读.幻象读.不可重复读 - 读取已提交(Read commit ...
- HDU-4791-Alice‘s Print Service
分析: 1.由于价格是递减的,所以可能出现si*pi>sj*pj(j>i).所以要有一个数组来储存当前端点的最小值. 2.然后二分查找当前的si,比较q*p[i]和M[i+1].不过在这之 ...
- UVa-340-猜数字
#include <stdio.h> char ans[1000],gus[1000]; int num[10]; int main() { int n,cnt=1; while (sca ...