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求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
随机推荐
- JavaScript学习笔记-setTimeout应用
setTimeout应用 var ids = [];function foo1(i) { this.i = i; console.log('i = '+i); ids[0] = setTimeout( ...
- ABAP 动态生成内表的几种方法
最近要写个程序,既有更新的,也有删除的,需要涉及到很多系统表,如果一个表一个表进行更新或者删除太慢了,于是就想通过创建动态内表来实现这些功能,在网上找了一些资料,经过多次尝试,终于测试成功了.网上讲述 ...
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
One of the most important considerations when writing a select statement against a large table is th ...
- 如何:对 SharePoint 列表项隐藏 ECB 中的菜单项
可以通过使用功能框架向编辑控制块 (ECB) 菜单添加新的自定义操作.但是,您不能使用此方法进行相反的操作,即隐藏现有的 ECB 菜单项,因为它们是通过使用 ECMAScript(JavaScript ...
- SharePoint 开启网站匿名访问图文详解
SharePoint 开启网站匿名,需要先开启web application的匿名访问,然后开启site的匿名访问.特别的,site可以选择整个网站开启或者列表和库开启匿名,如果选择列表和库开启匿名, ...
- SharePoint Server 2016 IT Preview 先睹为快
1.首先下载SharePoint Server 2016 IT Preview安装包,大约2.8GB,当然如果有需要,还可以下载两种提供测试的语言包,其他语言包还未提供下载,如下图: 2.我是在已经安 ...
- 使用Masonry搭建特殊布局时与xib的对比
之前只有比较浅的接触过Masonry.项目中大多数的布局还是用xib中的AutoLayout与手码的frame计算相结合,相信也会有很多项目和我一样是这两种布局的组合.其实xib各方面用的感觉都挺好, ...
- Android Material design
1.Material Design:扁而不平 2.Android Support Design 库 之 Snackbar使用及源码分析 3.十大Material Design开源项目,直接拿来用!
- Android - 模块添加与编译
Android5.1 Ubuntu14.04 Android系统编译依靠.mk文件 添加google服务 我们自己的ROM里没有google服务 完整的google包里包含google框架和各种服务, ...
- Facebook开源动画库 POP-POPBasicAnimation运用
动画在APP开发过程中还是经常出现,将花几天的时间对Facebook开源动画库 POP进行简单的学习:本文主要针对的是POPBasicAnimation运用:实例源代码已经上传至gitHub,地址:h ...