题目链接

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. 知方可补不足~Sqlserver发布订阅与sql事务的关系

    回到目录 前几讲说了一下通过sqlserver的发布与订阅来实现数据的同步,再通过EF这个ORM架构最终实现架构系统的读写分离,而在使用发布与订阅来实现数据同步时,需要我们注意几点,那就是当操作被使用 ...

  2. 开源MVCPager

    PagedList<EntityName> list = filterList.OrderBy(m => m.Exp1).Reverse().ToPagedList2(id, );/ ...

  3. Struts2学习笔记 - Action篇<配置文件中使用通配符>

    有三种方法可以使一个Action处理多个请求 动态方法调用DMI 定义逻辑Acton 在配置文件中使用通配符 这里就说一下在配置文件中使用通配符,这里的关键就是struts.xml配置文件,在最简单的 ...

  4. GOF设计模式特烦恼

    这段时间,学习状态比较一般,空闲时基本都在打游戏,和研究如何打好游戏,终于通过戏命师烬制霸LOL,玩笑了.为了和"学习"之间的友谊小船不翻,决定对以往学习过的GOF设计模式做一个简 ...

  5. 利用SSIS的ForcedExecutionResult 属性 和CheckPoint调试Package

    1,ForcedExecutionResult 强制一个package或task执行的结果,共有四种值 None,Success,Failure,Completion,默认值是None,表示不强制返回 ...

  6. LLBL Gen Pro 4.2 Lite 免费的对象关系映射开发框架与工具

    LLBL Gen Pro是一款优秀的对象关系映射开发框架,自2003年发布以来,一直有广泛的客户群.LLBL Gen Pro有几个标志性的版本,2.5/2.6是一个很稳定的版本,公司的一些旧的项目仍然 ...

  7. (转)Shell函数

    Shell函数类似于Shell脚本,里面存放了一系列的指令,不过Shell的函数存在于内存,而不是硬盘文件,所以速度很快,另外,Shell还能对函数进行预处理,所以函数的启动比脚本更快. 1.  函数 ...

  8. 关于pt与px

    pt:point,点,是印刷业一个标准的长度单位,1pt=1/72英寸:  在Windows里,默认的显示设置中,把文字定义为96dpi.这说明了:1px=1/96英寸:而1pt=1/72英寸,可以得 ...

  9. MongoDB的学习--索引类型和属性

    索引类型 MongDB的索引分为以下几种类型:单键索引.复合索引.多键索引.地理空间索引.全文本索引和哈希索引 单键索引(Single Field Indexes) 在一个键上创建的索引就是单键索引, ...

  10. HTML5移动Web开发(八)——避免文本字体大小重置

    适用设备:iOS.Windows Mobile在一些移动设备上,比方说iPhone,Windows Mobile,当用户把手机切换到横屏时,浏览器会自动地重置文本字体大小.这可能会对我们造成困扰,因为 ...