AC日记——Dividing poj 1014
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 69575 | Accepted: 18138 |
Description
Input
The last line of the input file will be "0 0 0 0 0 0"; do not process this line.
Output
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
#include<cstdio>
#include<cstring> using namespace std; int a[],sum_value=,ci[][],now=; bool dp[][]; bool Check_Answer()
{
memset(dp,false,sizeof(dp));
dp[][]=true;
for(int i=;i<=;i++)
{
for(int j=;j<=sum_value;j++)
{
if(dp[i][sum_value]) return true;
if(dp[i-][j])
{
for(int v=;v<=a[i];v++) dp[i][j+ci[i][v]]=true;
}
}
}
if(dp[][sum_value]) return true;
else return false;
} int main()
{
bool if_break;
while()
{
if_break=true,sum_value=,now++;
for(int i=;i<=;i++)
{
scanf("%d",&a[i]);
if(a[i]) if_break=false;
sum_value+=a[i]*i;
for(int j=;j<=a[i];j++) ci[i][j]=i*j;
}
if(if_break) break;
if(sum_value%)
{
printf("Collection #%d:\nCan't be divided.\n\n",now);
continue;
}
sum_value/=;
if(Check_Answer()) printf("Collection #%d:\nCan be divided.\n\n",now);
else printf("Collection #%d:\nCan't be divided.\n\n",now);
}
return ;
}
另附我的一个失败代码:
#include<cstdio>
#include<cstring> using namespace std; int a[],sum_value,num,ci[],flag; bool dp[]; int main()
{
int now=;
while()
{
now++;
memset(dp,false,sizeof(dp));
sum_value=,num=,flag=;
bool if_break=true;
for(int i=;i<=;i++)
{
scanf("%d",&a[i]);
sum_value+=a[i]*i,num+=a[i];
if(a[i]!=)
{
if_break=false;
for(int j=flag;j<flag+a[i];j++) ci[j]=i;
flag+=a[i];
}
}
if(if_break) break;
if(sum_value%)
{
printf("Collection #%d:\nCan't be divided.\n\n",now);
continue;
}
sum_value/=;
int max_now=;
dp[]=true;
for(int i=;i<=num;i++)
{
int max_now_=max_now;
for(int j=;j<=max_now;j++)
{
if(dp[j])
{
dp[j+ci[i]]=true;
if(j+ci[i]==sum_value)
{
printf("Collection #%d:\nCan be divided.\n\n",now);
if_break=true;
break;
}
if(j+ci[i]>max_now_&&j+ci[i]<=sum_value) max_now_=j+ci[i];
}
}
max_now=max_now_;
if(if_break) break;
}
if(if_break) continue;
printf("Collection #%d:\nCan't be divided.\n\n",now);
}
return ;
}
AC日记——Dividing poj 1014的更多相关文章
- AC日记——Tree poj 3237
Tree Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 9233 Accepted: 2431 Description ...
- AC日记——Crane poj 2991
POJ - 2991 思路: 向量旋转: 代码: #include <cmath> #include <cstdio> #include <cstring> #in ...
- AC日记——pigs poj 1149
POJ - 1149 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include <iostream> # ...
- Dividing POJ - 1014 多重背包二进制优化
多重背包模型 写的时候漏了一个等号找了半天 i<<=1 !!!!!! #include<iostream> #include<cstdio> #include&l ...
- AC日记——Dining poj 3281
[POJ-3281] 思路: 把牛拆点: s向食物连边,流量1: 饮料向t连边,流量1: 食物向牛1连边,流量1: 牛2向饮料连边,流量1: 最大流: 来,上代码: #include <cstd ...
- AC日记——Two poj 1849
Two 思路: 树形DP求直径: 答案是边权总和*2-直径: dp[i][1]::以i为根的子树中最长的路径: dp[i][0]::以i为根的子树中次长的路径: 来,上代码: #include < ...
- AC日记——Oulipo poj 3461
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37958 Accepted: 15282 Description The ...
- 证明 poj 1014 模优化修剪,部分递归 有错误
这个问题是存在做.我发现即使是可行的一个问题,但不一定正确. 大部分数据疲软,因为主题. id=1014">poj 1014 Dividing 题目大意:有6堆石头,权重分别为1 2 ...
- AC日记——codevs1688求逆序对
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
随机推荐
- angularjs封装bootstrap官网的时间插件datetimepicker
背景:angular与jquery类库的协作 第三方类库中,不得不提的是大名鼎鼎的jquery,现在基本上已经是国内web开发的必修工具了.它灵活的dom操作,让很多web开发人员欲罢不能.再加上已经 ...
- [deviceone开发]-do_Socket组件示例
一.简介 do_Socket只实现了socket的客户端的功能,这个示例完整了展示了组件的基本用法,需要和sockettest3工具配合使用,sockettest3做为一个socket server来 ...
- 转载:HBASE配置说明
HBase 默认配置 ,原文:http://eclecl1314-163-com.iteye.com/blog/1474286 该文档是用hbase默认配置文件生成的,文件源是 hbase-defa ...
- 为Autodesk Viewer添加自定义工具条
如果你参加过我们近期的活动,你就会频繁的听到我们现在正在做的Autodesk Viewer大模型浏览器,这是一个不需要下载任何插件,基于WebGL技术的浏览器,可以支持几十种数据格式.同时viewer ...
- ZeroMq安装包的生成【ubuntu10】
生成方法添加源sudo add-apt-repository ppa:chris-lea/zeromqsudo add-apt-repository ppa:chris-lea/libpgmsudo ...
- 之三:CAAnimationGroup - 动画组
动画组顾名思义就是将多个不同的动画效果组合起来同时作用于一个层上 代码演示: // 创建基本路径 CGMutablePathRef path = CGPathCreateMutable(); // 设 ...
- [Android]使用RecyclerView替代ListView(一)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4232560.html RecyclerView是一个比List ...
- xmpp整理笔记:环境的快速配置(附安装包)
现在虽然环信的xmpp框架很火,但是也有一些弊端.环信的框架部分代码不开源,而且收费模式不科学,用户量一直低于免费线则好,一旦超过,收费极高. xmpp感觉还是从xmppFramework框架学起比较 ...
- 【代码笔记】iOS-多张图片合成一张
代码: RootViewController.m #import "RootViewController.h" @interface RootViewController () @ ...
- OC self = [super init] , 点语法 , @property
OC self = [super init] , 点语法 , @property 构造方法为啥这么写? self = [super init]; [super init] 的结果可能有三种: 第一种: ...