HDOJ1059(多重部分和问题)
#include<cstdio>
#include<cstring>
using namespace std;
const int SIZE=+;
int a[];
int dp[SIZE];
bool check()
{
for(int i=;i<;i++)
if(a[i]!=)
return true;
return false;
}
int sum; int main()
{
int t=;
while(true)
{
sum=;
for(int i=;i<;i++)
{
scanf("%d",&a[i]);
sum+=(i+)*a[i];
}
if(!check())
break; printf("Collection #%d:\n",++t);
if(sum%==)
{
printf("Can't be divided.\n");
}
else
{
memset(dp,-,sizeof(dp));
int k=sum/;
dp[]=;
for(int i=;i<;i++)
{
for(int j=;j<=k;j++)
{
if(dp[j]>=)
{
dp[j]=a[i];
}
else if(j<(i+)||dp[j-(i+)]<=)
{
dp[j]=-;
}
else
{
dp[j]=dp[j-(i+)]-;
}
}
}
if(dp[k]>=)
{
printf("Can be divided.\n");
}
else
{
printf("Can't be divided.\n");
}
}
printf("\n");
}
return ;
}
HDOJ1059(多重部分和问题)的更多相关文章
- POJ_1742_Coins_(动态规划,多重部分和)
描述 http://poj.org/problem?id=1742 n种不同面额的硬币 ai ,每种各 mi 个,判断可以从这些数字值中选出若干使它们组成的面额恰好为 k 的 k 的个数. 原型: n ...
- COJ 0557 4013多重部分和问题
4013多重部分和问题 难度级别:B: 运行时间限制:2000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 n种大小不同的数字 Ai,每种各Mi个,判断是否可以从 ...
- HDOJ1059(多重背包)
1.解法一:多重背包 #include<iostream> #include<cstdio> using namespace std; #define MAX(a,b) (a& ...
- 编程算法 - 多重部分和问题 代码(C)
多重部分和问题 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 有n种不同大小的数字a, 每种各m个. 推断能否够从这些数字之中选出若干使它们的 ...
- HDU2844(多重部分和)
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 多重部分和 poj1742
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- 题解报告:hdu 2844 & poj 1742 Coins(多重部分和问题)
Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...
- 题解报告:hdu 1059 Dividing(多重背包、多重部分和问题)
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- DP的初级问题——01包、最长公共子序列、完全背包、01包value、多重部分和、最长上升子序列、划分数问题、多重集组合数
当初学者最开始学习 dp 的时候往往接触的是一大堆的 背包 dp 问题, 那么我们在这里就不妨讨论一下常见的几种背包的 dp 问题: 初级的时候背包 dp 就完全相当于BFS DFS 进行搜索之后的记 ...
随机推荐
- EventLoop(netty源码死磕4)
精进篇:netty源码 死磕4-EventLoop的鬼斧神工 目录 1. EventLoop的鬼斧神工 2. 初识 EventLoop 3. Reactor模式回顾 3.1. Reactor模式的组 ...
- 算法调参 weight_ratio, weight_seqratio
from openpyxl import Workbook import xlrd import time import Levenshtein as Le target_city_list = [' ...
- PHP自定义函数: 下载远程文件
function httpcopy($url, $file="", $timeout=60) { $file = empty($file) ? pathinfo($url,PATH ...
- 浅谈公平组合游戏IGC
浅谈公平组合游戏IGC IGC简介 一个游戏满足以下条件时被叫做IGC游戏 (前面三个字是自己YY的,不必在意) 竞争性:两名玩家交替行动. 公平性:游戏进程的任意时刻,可以执行的操作和操作者本人无关 ...
- JVM类加载器
系统中的类加载器 1.BootStrap ClassLoader a.启动ClassLoader b.加载rt.jar 2.Extension ClassLoader a.扩展ClassLoader ...
- 从springmvc启动日志学习
javaee标准中,tomcat等web容器启动时走web.xml 先将各种contex-param 放到servletcontxt中变成parameter,然后开始启动容器,容器对外提供了liste ...
- Django下MEDIA_ROOT, MEDIA_URL, STATIC_ROOT, STATIC_URL解惑
Django中settings中的四个设置参数的一些故事: MEDIA_ROOT, MEDIA_URL, STATIC_ROOT, STATIC_URL 1.MEDIA_ROOT与MEDIA_URL ...
- template.helper 检测浏览器 时间转换
template.helper('changeTime',function getLocalTime(nS) { var b=nS.substr(6,13); var c=parseInt(b) va ...
- ICCV 2015 B-CNN细粒度分类
哈哈,好久没写博客了....最近懒癌发作~~主要是因为心情不太好啊,做什么事情都不太顺心,不过已经过去啦.最近一直忙着公司的项目,想用这个网络,就给大家带来了的这篇文章.可能比较老,来自ICCV 20 ...
- rewrite_static
<?php class MyObject { public static $myStaticVar = 0; function myMethod() { self::$myStaticVar + ...