UVA 562 Dividing coins (01背包)
//平分硬币问题
//对sum/2进行01背包,sum-2*dp[sum/2]
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std; int value[],dp[]; int main()
{
int n,m,sum,sum1;
cin>>n;
while(n--)
{
cin>>m;
sum=;
for(int i=;i<=m;i++)
{
cin>>value[i];
sum+=value[i];
}
sum1=sum/;
memset(dp,,sizeof(dp));
for(int i=;i<=m;i++)
for(int j=sum1;j>=value[i];j--)
dp[j]=max(dp[j],dp[j-value[i]]+value[i]);
cout<<sum-*dp[sum1]<<endl;
}
return ;
}
UVA 562 Dividing coins (01背包)的更多相关文章
- UVA 562 Dividing coins --01背包的变形
01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostre ...
- UVA 562 Dividing coins(dp + 01背包)
Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were figh ...
- uva 562 Dividing coins(01背包)
Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were f ...
- UVA 562 Dividing coins (01背包)
题意:给你n个硬币,和n个硬币的面值.要求尽可能地平均分配成A,B两份,使得A,B之间的差最小,输出其绝对值.思路:将n个硬币的总价值累加得到sum, A,B其中必有一人获得的钱小于等于sum/2 ...
- UVA 562 Dividing coins 分硬币(01背包,简单变形)
题意:一袋硬币两人分,要么公平分,要么不公平,如果能公平分,输出0,否则输出分成两半的最小差距. 思路:将提供的整袋钱的总价取一半来进行01背包,如果能分出出来,就是最佳分法.否则背包容量为一半总价的 ...
- UVa 562 - Dividing coins 均分钱币 【01背包】
题目链接:https://vjudge.net/contest/103424#problem/E 题目大意: 给你一堆硬币,让你分成两堆,分别给A,B两个人,求两人得到的最小差. 解题思路: 求解两人 ...
- UVA 562 Dividing coins【01背包 / 有一堆各种面值的硬币,将所有硬币分成两堆,使得两堆的总值之差尽可能小】
It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nic ...
- uva562 Dividing coins 01背包
link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 562 Dividing coins
题目描述:给出一些不同面值的硬币,每个硬币只有一个.将这些硬币分成两堆,并且两堆硬币的面值和尽可能接近. 分析:将所有能够取到的面值数标记出来,然后选择最接近sum/2的两个面值 状态表示:d[j]表 ...
随机推荐
- [Android]Android SDk Manager中创建模拟器无法选择CPU问题解析
方法一.正常下载所需sdk包 启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Setti ...
- HTML,CSS,JS,JQ
CSS: <style> <!--属性选择器--> .container input[type="text"][name="txt"]{ ...
- Thymeleaf 3与Spring MVC 4 整合配置
Thymeleaf 3与Spring MVC 4 整合配置 Maven 依赖配置 Spring 相关依赖就不说了 <dependency> <groupId>org.thyme ...
- iOS UIImageView自适应图片大小
窗口大小获取: CGRect screenBounds = [ [UIScreenmainScreen]bounds];//返回的是带有状态栏的Rect CGRect rect = [ [UIScre ...
- excel 导入 与 导出
Excel导入 public ActionResult Excel(HttpPostedFileBase file) { HttpPostedFileBase fi ...
- python绝技 — 用Scapy测试无线网卡的嗅探功能
代码 #!/usr/bin/python #--*--coding=utf-8--*-- from scapy.all import * def pktPrint(pkt): if pkt.hasla ...
- c++中宽字节表示
1.C++语言中_T Visual C++里边定义字符串的时候,用_T来保证兼容性,VC支持ascii和unicode两种字符类型,用_T可以保证从ascii编码类型转换到unicode编码类型的时候 ...
- MocorDroid编译工程快速建立编译环境
function sprdLunch(){ declare -a arrProj arrProj=`find out/target/product -name previous_build ...
- ECOS-Ecstore证书生产失效问题排查
无法生成证书问题排查 无法生成证书问题排查 author :James,jimingsong@vip.qq.com since :2015-03-02 名称解释(官方) 常见错误 1. 名称解释(官方 ...
- Chloe and pleasant prizes
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...