描述

Two companies cooperatively develop a project, but they don’t like working with one another. In order to keep the company together, they have decided that only one of them will work on each job. To keep things fair, the jobs need to be split so that both work the same amount. This is accomplished by estimating the time necessary for each job and assigning jobs based upon these  estimates. The purpose of your program is to determine whether the jobs can be equally split (the total estimated time necessary for both individuals sums to the same value).

输入

The input will consist of multiple test cases (one per line terminated
by a line containing the string END). Each line will contain a space
seperated list of integers which are the estimated times required for
the jobs.

输出

For each case your output should be either YES or NO depending on whether they can be split equally.

样例输入

1 2 3 4 5 6
2 3 4 5 6 8
7 2 4 8 11 16
9 10 11 30
14 12 9 15
END

样例输出

NO
YES
YES
YES
NO

题目来源

TOJ

01背包问题,背包问题只会01了。%>_<%

#include <stdio.h>
#include <string.h>
#include <stdlib.h> int n,w[50001]={0};
int best[2][50001],sum,c; int main()
{
char ch[52000];
while(gets(ch),strcmp(ch,"END")!=0){
//初始化
int n=1,sum=0;
char *p=strtok(ch," ");
w[n]=atoi(p);
sum+=w[n++];
while(p=strtok(NULL," ")){
w[n]=atoi(p);
sum+=w[n++];
}
c=sum/2;
n--;
memset(best[0],0,sizeof(best[0]));
for(int i=1;i<=n;i++){
for(int j=1;j<=c;j++){
if(j>=w[i]){
if(best[(i-1)%2][j-w[i]]+w[i]>=best[(i-1)%2][j]){
best[i%2][j]=best[(i-1)%2][j-w[i]]+w[i];
}else {
best[i%2][j]=best[(i-1)%2][j];
}
}else{
best[i%2][j]=best[(i-1)%2][j];
}
}
}
if(best[n%2][c]==sum-best[n%2][c]) {
puts("YES");
}else{
puts("NO");
}
}
return 0;
}

TOJ 4119 Split Equally的更多相关文章

  1. Problem C: Celebrity Split

    题目描写叙述 Problem C: Celebrity Split Jack and Jill have decided to separate and divide their property e ...

  2. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

  3. 第十二届浙江省大学生程序设计大赛-Capture the Flag 分类: 比赛 2015-06-26 14:35 10人阅读 评论(0) 收藏

    Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer security, Ca ...

  4. Capture the Flag(模拟)

    Capture the Flag Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge In computer se ...

  5. Divide Candies CodeForces - 1056B (数学)

    Arkady and his friends love playing checkers on an n×nn×n field. The rows and the columns of the fie ...

  6. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第三部分)

    Earthstone Keeper Time Limit: 4 Seconds      Memory Limit: 65536 KB Earthstone Keeper is a famous ro ...

  7. CSS:Tutorial one

    1.Three Ways to Insert CSS External style sheet Internal style sheet Inline style External Style She ...

  8. 2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

    Little Boxes Problem Description Little boxes on the hillside.Little boxes made of ticky-tacky.Littl ...

  9. hdu6229 Wandering Robots 2017沈阳区域赛M题 思维加map

    题目传送门 题目大意: 给出一张n*n的图,机器人在一秒钟内任一格子上都可以有五种操作,上下左右或者停顿,(不能出边界,不能碰到障碍物).题目给出k个障碍物,但保证没有障碍物的地方是强联通的,问经过无 ...

随机推荐

  1. XE中rectangle实现渐变

    Fill -> Kind -> Gradient(选项) -> Gradient(Edit) 添加颜色即可

  2. Thumbnail 图片帮助

    public class Thumbnail { private Image srcImage; private string srcFileName; /// <summary> /// ...

  3. linux select 返回值

    IBM AIX上 select返回值的 man if  a connect-based socket is specified in the readlist parameter and the co ...

  4. MariaDB 一些SQL语句的执行

    通过拼接的TAG_NAME字符串获取对应的TAG_ID字符串 形如: '丹药|练功流|轻松|学生|学院风' 查询结果:'10|35|36|40' SELECT GROUP_CONCAT(TAG_ID ...

  5. Qt中QBitmap 的使用 --QBitmap的作用

    特别注意:如果想把做一个先把图画在内存中,在显示到页面,不要使用bitmap,这个只有单色: 一般情况下QBitmap只作为图片掩码使用,比如做不规则窗口. QBitmap表示一种只有黑白的单色图片, ...

  6. java关键字(更新)

    1.final: ①final修饰类:该类不能被继承: ②final修饰方法:该方法不能被子类重写: ③final修饰变量:一.修饰基本数据类型变量,必须初始化,且值不能被改变:二.修饰引用数据类型变 ...

  7. NSArray 数组

    前言 数组只能存储 OC 对象,不能存储 C 语言中的基本数据类型,也不能存储 nil . Xcode 7 对系统中常用的一系列容器类型都增加了泛型支持(),有了泛型后就可以指定容器类中对象的类型了. ...

  8. SQL Server 数据类型与.Net Framework平台映射

    SQL Server 和 .NET Framework 基于不同的类型系统.  例如,.NET Framework Decimal 结构的最大小数位数为 28,而 SQL Server 的 decim ...

  9. How to: Create a Business Model in the XPO Data Model Designer

    How to: Create a Business Model in the XPO Data Model Designer This topic provides step-by-step inst ...

  10. python 获得毫秒级时间戳

    import time import datetime t = time.time() print (t) #原始时间数据 print (int(t)) #秒级时间戳 print (int(round ...