题目描写叙述

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. [洛谷P3121] 审查(黄金) (AC自动机)

    题目描述 FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S.他有一个包含n个单词的列表,列表里的n个单词记为t_1...t_N.他希望从S中删除这些单词. FJ每次在S中找 ...

  2. C++函数指针相关 & 类成员的指针 & 成员函数的指针

    有时候会有指向类成员变量或者成员函数的指针,但是注意,这个指针并不是针对一个地址的指向,而更多的是一个偏移. 同时,支持将父类对象的成员 转为 子类对象的成员指针,如下: 反过来,是不行的.因为父类的 ...

  3. [LeetCode]Single Number 异或的妙用

    1.数组中仅仅有一个元素仅仅出现一次,其余出现偶数次. 利用异或中同样元素相互抵消的方式求解. 2.数组中仅仅有2个元素仅仅出现一次.其余出现偶数次. class Solution { public: ...

  4. iBatis框架使用 4步曲

    iBatis是一款使用方便的数据訪问工具,也可作为数据持久层的框架.和ORM框架(如Hibernate)将数据库表直接映射为Java对象相比.iBatis是将SQL语句映射为Java对象. 相对于全自 ...

  5. avalon 笔记---Mr.wing

    Avalon笔记步骤一:引用js文件<script src="js/avalon.js"></script>步骤二:<script> var v ...

  6. 安装vnc出现的问题

    重启vnc 命令:/sbin/service vncserver start或者vncserver VNC的启动/停止/重启 #service vncserver start/stop/restart ...

  7. BZOJ 4034 线段树+DFS序

    思路: 先搞出来每个点的DFS序 (要有入栈和出栈两种状态的) 处理出来 线段树区间有多少入栈的和多少出栈的 加区间的时候就加(入-出)*wei 查前缀和 //By SiriusRen #includ ...

  8. 线性同余同余方程组解法(excrt)

    [问题描述] 求关于 x 的同余方程组 x%a 1 =b 1  a1=b1 x%a 2 =b 2  a2=b2 x%a 3 =b 3  a3=b3 x%a 4 =b 4  a4=b4 的大于等于 0 ...

  9. 通过视频展示如何通过Samba配置PDC

    通过视频展示如何通过Samba配置PDC(Linux企业应用案例精解补充视频内容) 本文通过视频,真实地再现了在Linux平台下如何通过配置smb.conf文件而实现Samba Server模拟win ...

  10. ES6特性-带标签的模板字符串(tagged template)

    tagged template: 加在模板字符串前面加一个标签(函数). let dessert = = '甜品' drink = '茶' let breakfast = kitchen`今天的早餐是 ...