题目链接

http://codeforces.com/gym/100917/problem/J

Description

standard input/output
Statements

The jury of Berland regional olympiad in informatics does not trust to contest management systems, so the Berland regional programming contest is judged by the next way. There are n judges in the jury, each judge have authority ai. When jury receives a diskette with the new solution, each jury member reads its source and votes "OK" or "WA". If after the voting ends the sum of authorities of jury members, who think that solution is correct, is equal or greater to p, then soluton is accepted, otherwise it is rejected.

Several jury members think, that current system is too complicated for them and proposed some changes: each jury member will have new authority bi, and limit is changed to q; then, in their opinion, calculations will be easier, and nothing more changes.

You are hired by the Department of Education of Berland region to check if the new system is equivalent to old one, i.e. that at any possible distribution of votes final verdict with the new and with the old parameters will be the same. If the systems differ, output an example of voting, when verdicts in both systems are different.

Input

First line of the input contains one integer n (1 ≤ n ≤ 100) — number of judges in the jury.

Second line contains n + 1 integers p, a1, a2, ..., an (1 ≤ p, ai ≤ 106) — the current acception limit and the current values of authorities of jury members, respectively.

Third line contains n + 1 integers q, b1, b2, ..., bn (1 ≤ q, bi ≤ 106) — the new acception limit and the new values of authorities of jury members, respectively.

Output

If old and new systems are equivalent, print "YES". Otherwise in the first line of output print "NO", and in second print example of voting, with different verdicts in old and new systems. Voting is encoded with the string of length n, where i-th character is '1', if i-th judge considered solution correct and '0' otherwise.

If several answers are possible, print any of them.

Sample Input

Input
3
8 4 5 6
2 1 1 1
Output
YES
Input
3
6 4 5 6
2 1 1 1
Output
NO
001 题意:输入n表示有n个评委,现在有两种裁决方案:1、 p a[1]、a[2]......a[n] 表示每个评委的权值,如果第i个评委同意则总的评分加上a[i],如果总分达到p则表示通过;
2、 q b[1]、b[2]......b[n] 与上面相同,如果总分达到q表示通过; 现在要求判断两种评选方案在任何情况下结果是否都是一样; 思路:定义mx[i]表示在第一种方案总分达到i(i<p)时,第二种方案能达到的最大得分,当在i<p&&mx[i]>=q时,则输出“NO” ,为了输出路径,可以使用bitset; 同样对调p和q a和b 再计算一次; 代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <bitset>
using namespace std;
typedef long long LL;
const int maxn=1e6+;
bitset<>s[maxn];
int a[],b[];
int mx[maxn];
int n; bool calc(int *a,int *b)
{
for(int i=; i<maxn; i++) s[i].reset();
memset(mx,-,sizeof(mx));
mx[]=;
int top=;
for(int i=; i<=n; i++)
{
for(int j=top; j>=; j--)
{
if(mx[j]>-)
{
if(j+a[i]<a[]&&mx[j]+b[i]>mx[j+a[i]])
{
mx[j+a[i]]=mx[j]+b[i];
s[j+a[i]]=s[j];
s[j+a[i]].set(i);
top=max(top,j+a[i]); }
if(j+a[i]<a[]&&mx[j+a[i]]>=b[])///一定要加上j+a[i]<a[0] 否则可能越界;
{
puts("NO");
for(int k=; k<=n; k++)
printf("%d",(int)s[j+a[i]][k]);
puts("");
return true;
}
}
}
}
return false;
} int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++) scanf("%d",&a[i]);
for(int i=; i<=n; i++) scanf("%d",&b[i]);
if(calc(a,b)) return ;
if(calc(b,a)) return ;
puts("YES");
return ;
}
 

Gym 100917J---Judgement(01背包+bitset)的更多相关文章

  1. hdu 5890 01背包 bitset

    注意不能每个T都mem 不然会T #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b, ...

  2. Gym 101102A Coins -- 2016 ACM Amman Collegiate Programming Contest(01背包变形)

    A - Coins Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Descript ...

  3. 回滚线段树+bitset优化01背包——cf981E

    /*首先考虑如何计算一个点的可能凑出的值,这就是一个01可行性背包问题那么再拓展到一段区间[1..n]的点上,每个query都可以看做是一段区间上的点[l,r]加上一个体积为x的物品,转换到01背包上 ...

  4. 01二维背包+bitset优化——hdu5890

    口胡一种别的解法: 三重退背包,g1[j]k]表示不选x的选了j件物品,体积为k的方案数,g[0][0] = 1 , g1[j][k]=dp[j][k]-g1[j-1][k-a[x]] 然后按这样再退 ...

  5. codeforce Gym 101102A Coins (01背包变形)

    01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstri ...

  6. HDU 3639 Bone Collector II(01背包第K优解)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. [HDOJ2639]Bone Collector II(第k优01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:求01背包的第k优解 dp(i, j)表示容量为j时的i优解 对于第二维的操作和01背包几 ...

  8. [HDOJ1171]Big Event in HDU(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 许多有价值的物品,有重复.问如何将他们分成两堆,使两堆价值之差最小. 对价值求和,转换成01背包 ...

  9. [HDOJ2546] 饭卡 (01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 先找出最贵的那个菜,这个菜一定是最后买的那个.然后再在前n-1个菜里做01背包.找出不超过m-5 ...

随机推荐

  1. Java集合框架的总结

    本篇文章先从整体介绍了Java集合框架包含的接口和类,然后总结了集合框架中的一些基本知识和关键点,并结合实例进行简单分析.当我们把一个对象放入集合中后,系统会把所有集合元素都当成Object类的实例进 ...

  2. CSS3_02之2D、3D动画

    1.转换属性:transform:取值:transform-function(转换函数): 2.转换原点:默认元素的中心处:更改转换原点:transform-origin:取值:数字/百分比/关键字: ...

  3. KnockoutJS 3.X API 第四章 数据绑定(2) 控制流foreach绑定

    foreach绑定 foreach绑定主要用于循环展示监控数组属性中的每一个元素,一般用于table标签中 假设你有一个监控属性数组,每当您添加,删除或重新排序数组项时,绑定将有效地更新UI的DOM- ...

  4. 找到SQL Server的序列号

          有时候希望获取当前机器上安装的SQL Server序列号,但注册表中序列号是经过加密的,因此我写了一个小工具获取当前SQL Server的序列号.程序比较粗糙,没有做错误验证.       ...

  5. java中的显示初始化和特定初始化

    public class Test{ public static void main(String[] args){ Child child = new Child(); } } class Pare ...

  6. Kruskal算法(一)之 C语言详解

    本章介绍克鲁斯卡尔算法.和以往一样,本文会先对克鲁斯卡尔算法的理论论知识进行介绍,然后给出C语言的实现.后续再分别给出C++和Java版本的实现. 目录 1. 最小生成树 2. 克鲁斯卡尔算法介绍 3 ...

  7. [c++] Associative Containers

    关联容器 和 顺序容器 的本质差别在于: 关联容器通过键(key)存储和读取元素,而顺序容器则通过元素在容器中的位置顺序存储和访问元素. Reference: http://www.cnblogs.c ...

  8. tomcat架构之-----基本概念

    一直都没有搞明白tomcat中server.service.Engine.Host.Context概念的意义,最近认真看了<Tomcat 6 Developer Guide>,有了进一步的 ...

  9. 20个漂亮 CSS3 按钮效果及优秀的制作教程

    在这篇文章中,我们编译了一组有用的 CSS3 动画按钮教程和引人注目的实验.正如我们都知道的,CSS3在网页设计方面是最重要和最关键的,可以使您的网站对访客更具吸引力和互动性.你可以学习这些教程和试验 ...

  10. GIF录制神器GifCam

    前几天偶然看到一款神器:GifCam! GifCam是什么? 一款录制gif动画图片的小软件,小到不足一兆. 使用方法(简单到不可思议) 百度 GifCam 下载: 不用安装,直接打开gifcam: ...