题目链接

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程序员的日常——SpringMVC+Mybatis开发流程、推荐系统

    今天大部分时间都在写业务代码,然后算是从无到有的配置了下spring与mybatis的集成. SpringMVC+Mybatis Web开发流程 配置数据源 在applicationContext.x ...

  2. Fedora 24 install MySQL

    Background I have work with mysql on the fedora OS, but currently fedora have no support mysql inste ...

  3. java之设计模式

    一.代理模式 a.抽象角色(接口):声明真实对象和代理对象的共同接口 b.代理角色:代理对象角色内部含有对真实对象的引用,从而可以操作真实对象,同时代理对象提供与真实对象相同的接口以便在任何时刻都能替 ...

  4. chrome远程调试真机上的app

    chrome远程调试真机上的app 看来要上真机了...

  5. iOS中计算磁盘缓存文件夹的大小

    SDWebImage框架中在自动做磁盘缓存的过程中,底层实现了计算Cache的大小,框架的方法名称是getSize,但方法不容易被人理解,我就从新写了一下,附带注释 基本思想: 1. 先取出的Cach ...

  6. ASP.NET中使用DataGrid控件按照条件显示GridView单元格的颜色

    问题描述: 我在做一个关于信用卡管理系统时遇到一个问题:信用卡内金额低于100元时,数字颜色显示为红色,其余显示为绿色 之前,尝试了修改成为模板列以及转换成Reapeater控件,甚至用了Jquery ...

  7. WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要针对WPF项目 ...

  8. 多个Jar包的合并操作

    原文:http://www.cnblogs.com/meteoric_cry/p/4283656.html 需求是将多个jar合并成一个jar的问题.这里列一下操作步骤: 1.将所有jar文件复制至某 ...

  9. CSS中常见的6种文本样式

    前面的话 CSS文本样式是相对于内容进行的样式修饰.由于在层叠关系中,内容要高于背景.所以文本样式相对而言更加重要.有些人对文本和字体样式之间的不同不太了解,简单地讲,文本是内容,而字体则用于显示这个 ...

  10. 如何线程安全地遍历List:Vector、CopyOnWriteArrayList

    遍历List的多种方式 在讲如何线程安全地遍历List之前,先看看通常我们遍历一个List会采用哪些方式. 方式一: for(int i = 0; i < list.size(); i++) { ...