题目描写叙述

Problem C: Celebrity Split

Jack and Jill have decided to separate and divide their property equally. Each of their N mansions has a value between 1,000,000
and 40,000,000 dollars. Jack will receive some of the mansions; Jill will receive some of the mansions; the remaining mansions will be sold, and the proceeds split equally.

Neither Jack nor Jill can tolerate the other receiving property with higher total value. The sum of the values of the mansions Jack receives must be equal to the sum of the values of the mansions Jill receives. So long as the value that each receives is equal,
Jack and Jill would like each to receive property of the highest possible value.

Given the values of N mansions, compute the value of the mansions that must be sold so that the rest may be divided so as to satisfy Jack and Jill.

Example

Suppose Jack and Jill own 5 mansions valued at 6,000,000, 30,000,000, 3,000,000, 11,000,000, and 3,000,000 dollars. To satisfy their requirements, Jack or Jill would receive the mansion worth 6,000,000 and the other would receive both manstions worth 3,000,000
dollars. The mansions worth 11,000,000 and 30,000,000 dollars would be sold, for a total of 41,000,000 dollars. The answer is therefore 41000000.

输入要求

The input consists of a sequence of test cases. The first line of each test case contains a single integer N, the number of mansions, which will be no more than 24. This line is followed by N lines, each giving the value of
a mansion. The final line of input contains the integer zero. This line is not a test case and should not be processed.

输出要求

For each test case, output a line containing a single integer, the value of the mansions that must be sold so that the rest may be divided so as to satisfy Jack and Jill.

假如输入

5
6000000
30000000
3000000
11000000
3000000
0

应当输出

41000000

#include<iostream>
#include<algorithm>
#include <vector>
#include<string.h>
#include<ctype.h>
#include<math.h>
using namespace std;
int sum[200],a[200],ans;
void fun();
void divide(int p,int diff,int hav)//p:剩余房子数,differ:两人差价,hav:两人共取走的钱
{
int i,j,n;
if(diff==0&&ans<hav)
ans=hav;
if(p<0)
return;
if(abs(diff)>sum[p])//剪枝1
return;
if(sum[p]+hav<ans)//剪枝2
return;
divide(p-1,diff+a[p],hav+a[p]);
divide(p-1,diff-a[p],hav+a[p]);
divide(p-1,diff,hav);
}
int main()
{
fun();
return 0;
}
void fun()
{
int n,i;
while(cin>>n&&n)
{
for(i=0;i<n;i++)
{
cin>>a[i];
if(i==0)
sum[i]=a[0];
else
sum[i]=sum[i-1]+a[i];
}
ans=0;
divide(n-1,0,0);
cout<<sum[n-1]-ans<<endl;
}
}

Problem C: Celebrity Split的更多相关文章

  1. TJU Problem 2548 Celebrity jeopardy

    下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548.   Celebrity jeopardy Time Limit: 1.0 Seconds   Memory Lim ...

  2. WordCount作业提交到FileInputFormat类中split切分算法和host选择算法过程源码分析

    参考 FileInputFormat类中split切分算法和host选择算法介绍  以及 Hadoop2.6.0的FileInputFormat的任务切分原理分析(即如何控制FileInputForm ...

  3. Common Pitfalls In Machine Learning Projects

    Common Pitfalls In Machine Learning Projects In a recent presentation, Ben Hamner described the comm ...

  4. Using zend-paginator in your Album Module

    Using zend-paginator in your Album Module TODO Update to: follow the changes in the user-guide use S ...

  5. MapReduce 模式、算法和用例(MapReduce Patterns, Algorithms, and Use Cases)

    在新文章“MapReduce模式.算法和用例”中,Ilya Katsov提供了一个系统化的综述,阐述了能够应用MapReduce框架解决的问题. 文章开始描述了一个非常简单的.作为通用的并行计算框架的 ...

  6. EM and GMM(Theory)

    Part 1: Theory 目录: What's GMM? How to solve GMM? What's EM? Explanation of the result What's GMM? GM ...

  7. Dream team: Stacking for combining classifiers梦之队:组合分类器

     sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  8. 谷歌的java文本差异对比工具

    package com.huawei.common.transfertool.utils; /** * @author Paul * @version 0.1 * @date 2018/12/11 * ...

  9. 可扩展的Web系统和分布式系统(Scalable Web Architecture and Distributed Systems)

    Open source software has become a fundamental building block for some of the biggest websites. And a ...

随机推荐

  1. Kubernetes本地私有仓库配置

    实验环境 master 10.6.191.181 node1 10.6.191.182 node2 10.6.191.183 本地私有仓库 10.6.191.184 一.安装本地私有仓库 1.安装do ...

  2. 搭建Lvs负载均衡群集

    一.Lvs详解 lvs内核模型 1.模型分析 用户访问的数据可以进入调度器 匹配调度器分配的虚拟IP|IP+端口(路由走向) 根据调度器的算法确定匹配的服务器 2.调度条件:基于IP.基于端口.基于内 ...

  3. Unity C# 设计模式(二)简单工厂模式

    定义: 简单工厂模式是属于创建型模式,又叫做静态工厂方法(Static Factory Method)模式,但不属于23种GOF设计模式之一. 简单工厂模式是由一个工厂对象决定创建出哪一种产品类的实例 ...

  4. 第二十四天 框架之痛-Spring MVC(四)

    6月3日,晴."绿树浓阴夏日长. 楼台倒影入池塘. 水晶帘动微风起, 满架蔷薇一院香". 以用户注冊过程为例.我们可能会选择继承AbstractController来实现表单的显示 ...

  5. Android调用camera错误setParameters failed深层解析

    1. Camera Camera是Android framework里面支持的,同意你拍照和拍摄视频的设备,那么,在使用camera开发中总是会遇到一些问题,比例如以下面这样子的: E/Android ...

  6. iOS 实现QQ界面

    应师傅要求编写个QQ界面来不吝赐教下我的代码问题. 编写个QQ界面.有三个组,每一个组有人.并显示在线不在线. 先看一下效果图 这里省了事由于我的图片仅仅用了一张.假设要依据人的不同设置,仅仅要在ce ...

  7. HBase源代码分析之HRegion上MemStore的flsuh流程(二)

    继上篇<HBase源代码分析之HRegion上MemStore的flsuh流程(一)>之后.我们继续分析下HRegion上MemStore flush的核心方法internalFlushc ...

  8. rac_grid自检提示缺少pdksh-5.2包

    原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...

  9. mysql二进制日志文件出错导致mysql服务无法启动

    今天打开phpmyadmin发现连不上mysql数据库,重新启动mysql启动不起来,查看日志发现例如以下错误 <span style="font-family:SimSun;font ...

  10. HtmlHelper的扩展分页方法

    一.新建一个空MVC项目,命名为MVCAppPager 二.新建一个文件夹PageHelper,在文件夹下新建接口IPageList以及实现类PageList IPageList接口: public ...