HDU1171(01背包均分问题)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
Input
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
Sample Input
Sample Output
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[];
int n;
int w[];
int main()
{
while(scanf("%d",&n)!=EOF&&n>=)
{
memset(dp,,sizeof(dp));
int sum=;
int v,num;
int cnt=;
for(int i=;i<n;i++)
{
scanf("%d%d",&v,&num);
sum+=num*v;
while(num)//将相同的设备分开
{
w[cnt++]=v;
num--;
}
} for(int i=;i<cnt;i++)
for(int j=sum/;j>=w[i];j--)
dp[j]=max(dp[j],dp[j-w[i]]+w[i]);
int ans=max(dp[sum/],sum-dp[sum/]);
printf("%d %d\n",ans,sum-ans);
} return ;
}
HDU1171(01背包均分问题)的更多相关文章
- UVA562(01背包均分问题)
Dividing coins Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descriptio ...
- POJ3211(trie+01背包)
Washing Clothes Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9384 Accepted: 2997 ...
- hihocoder 1038 01背包
#1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励 ...
- 1171 Big Event in HDU 01背包
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. ...
- poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
题目链接: id=3211">poj3211 hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
- POJ1112 Team Them Up![二分图染色 补图 01背包]
Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7608 Accepted: 2041 S ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- 51nod1085(01背包)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...
随机推荐
- xterm.js 基于websocket 链接容器 命令行工具
<template> <div> <el-dialog title="命令" :visible.sync="dialogTableVisib ...
- C++11 并发指南四(<future> 详解一 std::promise 介绍)(转)
前面两讲<C++11 并发指南二(std::thread 详解)>,<C++11 并发指南三(std::mutex 详解)>分别介绍了 std::thread 和 std::m ...
- java new一个接口到底要做什么
转自:http://www.cnblogs.com/yjmyzz/p/3448330.html java中的匿名类有一个倍儿神奇的用法,见下面代码示例: 1 package contract; 2 3 ...
- iOS 私有库的使用
最近项目说要用私有库 主要过程 创建两个库: 索引库 组件库 组件库 用git操作 比如更新代码 push 打tag等 索引库 存放组件的描述信息 也就是 .spec文件 这个文件和 ...
- android等待旋转圆圈动画
先创建一个动画的xml文件例如以下 <? xml version="1.0" encoding="utf-8"?> <animation-li ...
- 李洪强iOS开发之带placeHolder的Textview
李洪强iOS开发之带placeHolder的Textview 01 - 创建工过程,定义全局属性,遵守textview的代理协议 02 - 添加一个textview和一个label 03 - 实现 ...
- EasyDarwin开源云平台接入海康威视EasyCamera摄像机之快照获取与上传
本文转自EasyDarwin团队成员Alex的博客:http://blog.csdn.net/cai6811376 EasyCamera开源摄像机拥有获取摄像机实时快照并上传至EasyDarwin云平 ...
- android studio发布公共类库到服务器maven仓库
在上一篇中提到了怎么创建私有maven库,这篇主要结合android studio的使用,直接进入正题,看以下步骤 1.创建android项目 创建Project,然后加一个library的modul ...
- JDBC编程步奏、问题总结(一)
jdbc编程步骤: 1. 加载数据库驱动 2. 创建并获取数据库链接 3. 创建jdbc statement对象 4. 设置sql语句 5. 设置sql语句中的参数(使用preparedStateme ...
- tornado安全应用之用户认证
在这个例子中,我们将只通过存储在安全cookie里的用户名标识一个人.当某人首次在某个浏览器(或cookie过期后)访问我们的页面时,我们展示一个登录表单页面.表单作为到LoginHandler路由的 ...