Kile and Pogi have found N​ banknotes on the street. After making sure that the original owneris nowhere to be found, they decided to split the banknotes amongst themselves.In the end they want to “win” the same amount of money so they split thebanknotes in such a way. Of course, the sum of the banknotes nobody ends uphaving is ​the least possible​one.

Since they couldn’t justleave the remaining banknotes on the street, they decided to go to a nearbycasino and put everything on ​red​, hoping that theywould end up getting twice the money they bet. The roulette decided on the(lucky, for this time) number 13 and our heroes decided to split the money theywon. The payout is such that Kile and Pogi will always be able to split themoney they won into two equal parts.

Because of the immense adrenaline rush, theboys have lost their mathematical abilities. Help them figure out how muchmoney each of them is taking home.

INPUT

 

The first line of input contains theinteger ​ ​      ​N (1 ≤ ​N ≤ 500) that denotes the number of banknotes on the street.

Each of thefollowing th     N​ lines contains a single positive integer ​​  ci that denotes the value of ​  the ​i banknote in kunas (kn). The total sum of money will not exceed 100000 kn. 

OUTPUT

 

You must output the amount of money each of them took home.

SCORING

In test cases worth 50 points total, ​    ​N will be less than orequal to 13.

In test cases worth 70 points total, ​    ​N will be less than orequal to 50, and the total sum of money will be at most 1000 kn.

SAMPLE TESTS

input

4

2 3 1 6

6

2 3 5 8 13

output

6


18


题意:给你n个数  求出一个最大的m  使得n个数能组成2个m  求sum-m

题解:定义dp[i][j]为前i个数  差为j  组成2个m的数目前最大的那个是多少

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[505][100005],a[505];
int main(){int n,i,j,sum=0;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&a[i]);sum+=a[i];}memset(dp,-1,sizeof(dp));dp[0][0]=0;for(i=1;i<=n;i++){for(j=0;j<=sum/2;j++){if(dp[i-1][j]!=-1)dp[i][j+a[i]]=max(dp[i-1][j]+a[i],dp[i][j+a[i]]);dp[i][j]=max(dp[i-1][j],dp[i][j]);if(j-a[i]<0){if(dp[i-1][j]!=-1)dp[i][abs(j-a[i])]=max(dp[i][abs(j-a[i])],dp[i-1][j]+abs(j-a[i]));}else{if(dp[i-1][j]!=-1)dp[i][j-a[i]]=max(dp[i-1][j],dp[i][j-a[i]]);}}}printf("%d\n",sum-dp[n][0]);return 0;
}

COCI 2016/2017 Round 4 C dp相关推荐

  1. COCI 2016/2017 Round #3 题解

    COCI 2016/2017 Round #3 这套题代码量似乎有些大呀...前五题代码都已经破4KB了... 而且还要卡空间.卡常数... Imena 题目翻译 分析 细节模拟题,注意可能会出现名字 ...

  2. COCI 2016/2017 Round #5题解

    COCI 2016/2017 Round #5 Tuna 题目翻译 分析 水题,按题意模拟即可. 参考代码 #include<cstdio> #include<algorithm&g ...

  3. 解题报告(一)D、(CROC 2016 - Final Round C)Binary Table(矩阵 + 状态压缩 + FWT)(3.5)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  4. Macbook pro 2016/2017 接入扩展坞时断 WIFI 问题的解决办法

    Macbook pro 2016/2017 接入扩展坞时断 WIFI 问题的解决办法 参考文章: (1)Macbook pro 2016/2017 接入扩展坞时断 WIFI 问题的解决办法 (2)ht ...

  5. 百度2016/2017秋招部分题目解析

    今天把百度2016/2017秋招剩余的4星题目,以及少部分有难度或者比较有趣味的3星题目来一起分析下,所以这次就来个合集了(共包含了4个题目),总体来看题目比较简单,所以分析也会写得相对简略一些.尽管 ...

  6. 2017上半年计算机教学计划,2016—2017学年度第二学期信息技术教学计划

    2016-2017学年度第二学期信息教学计划 小学信息教学是一门极为重要的课程,顺应了时代需求,从小就要开始接触这门课程,才会适应社会的发展进步,开始肯定有点困难,但是希望大家能够保持学好的决心,能够 ...

  7. 哈师大计算机学院2016级新生,【通知公告】哈尔滨师范大学2016—2017学年度国家励志奖学金获奖学生初审名单公示...

    原标题:[通知公告]哈尔滨师范大学2016-2017学年度国家励志奖学金获奖学生初审名单公示 按照黑龙江省学生资助管理中心<关于上报2017年秋季高校奖学金评审等相关材料的通知>(黑教助中 ...

  8. [转]KSN报告:2016 - 2017年的勒索软件

    目录 简要介绍一年内勒索软件的演变 Ransomware-as-a-Service的兴起 针对性攻击的增长 主要数字 结论和预测 预测 反击 本报告是使用卡巴斯基安全网络(KSN)处理的非个性化数据编 ...

  9. Codeforces Beta Round #2--B题 (DP)

    题目:The least round way 1000*1000的方阵,每个格子有一个非负整数,现在要从左上走到右下,每次只能向下或者向右走.目标是使得所有走的格子里的数的乘积里,末尾0的个数最少,要 ...

  10. lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP

    E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...

最新文章

  1. 一篇文章带你从认识Python装饰器到熟练使用
  2. Codeforces Global Round 3 A. Another One Bites The Dust
  3. 【POJ - 1062】【nyoj - 510】昂贵的聘礼 (Dijkstra最短路+思维)
  4. 20145203盖泽双《网络对抗技术》拓展:注入:shellcode及return-into-libc攻击
  5. 初探 performance – 监控网页与程序性能
  6. 字符串hash(类似于进制的hash)
  7. java常量表达式区别_java编译器对string常量表达式的处理和优化
  8. RabbitMQ中Confirm确认与Return返回消息详解(八)
  9. pc机收集信息cpu\配置\网络信息
  10. 中职计算机ps教案ppt,photoshop课件ppt
  11. String s1 = new String(abc)到底创建了几个对象?底层原理是什么?
  12. 【NLP】模型压缩与蒸馏!BERT的忒修斯船
  13. 一组匹配手机号码的正则表达式
  14. HZNUOJ 2058 凯撒密码
  15. Java正则表达式(超详细)
  16. 整理的AD/2000技巧
  17. cvx怎么处理向量和向量共轭转置的乘积_矩阵论练习2(共轭转置的秩和解空间)...
  18. 数据库查询_同时选修了两门课的学生姓名、学号
  19. python从键盘输入一个列表计算输出元素的平均值_从键盘输入一个列表,计算输出列表元素的平均值。 输入输出示例: 输入 [2,3,5,7] 输出 平均...
  20. 如何使用开源工具构建您的网络安全工具包

热门文章

  1. 记录m3u8变成图片的解决办法
  2. c语言中nop的作用,单片机c语言编程里的nop()含义是什么?
  3. LICEcap 简洁易用的动画屏幕录制软件
  4. WatchGuard 防火墙封 Msn qq icq
  5. 即将来临的Rails 4.0将放弃Ruby 1.8支持,改进后台任务、缓存等多项内容
  6. 电脑如何录屏?分享4个屏幕录制的好方法,建议收藏
  7. ios 微信登录sdk集成
  8. 《富爸爸穷爸爸》读书笔记
  9. 差分与反差分计算(MATLAB)
  10. ept技术_每天5分钟跟我一起学电气之EPT的原理