Gym 100917J---Judgement(01背包+bitset)

题目链接

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+5;
bitset<120>s[maxn];
int a[105],b[105];
int mx[maxn];
int n;bool calc(int *a,int *b)
{for(int i=0; i<maxn; i++)  s[i].reset();memset(mx,-1,sizeof(mx));mx[0]=0;int top=0;for(int i=1; i<=n; i++){for(int j=top; j>=0; j--){if(mx[j]>-1){if(j+a[i]<a[0]&&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[0]&&mx[j+a[i]]>=b[0])///一定要加上j+a[i]<a[0] 否则可能越界;
                {puts("NO");for(int k=1; k<=n; k++)printf("%d",(int)s[j+a[i]][k]);puts("");return true;}}}}return false;
}int main()
{scanf("%d",&n);for(int i=0; i<=n; i++)    scanf("%d",&a[i]);for(int i=0; i<=n; i++)    scanf("%d",&b[i]);if(calc(a,b)) return 0;if(calc(b,a)) return 0;puts("YES");return 0;
}
 

转载于:https://www.cnblogs.com/chen9510/p/5930242.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/417985.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

raid5 合适 多少块硬盘_raid1 raid2 raid5 raid6 raid10如何选择使用?各需要几块硬盘?...

我们在做监控项目存储时&#xff0c;经常会用到磁盘阵列&#xff0c;什么是磁盘阵列呢&#xff1f;那为什么要做磁盘阵列呢&#xff1f;raid1 raid2 raid5 raid6 raid10各有什么优势&#xff1f;本期我们来看下。一、什么是Raid&#xff1f;它有什么作用&#xff1f;1、什么是R…

常用设置

Windows Registry Editor Version 5.00 (加快程序运行速度)[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]"NtfsDisable8dot3NameCreation"dword:00000000"Win31FileSystem"dword:00000000"Win95TruncatedExtensions"dword:…

SpringMVC 源码学习 返回值处理

SpringMVC中对返回值的数据基本分为两类&#xff1a; 1、响应数据 2、响应页面 一、响应数据 响应数据大多数都是将返回值的格式转换为JSON格式然后展示在页面或者保存i起来。 第一步&#xff1a;在SpringBoot中需要引入json场景 <dependency><groupId>org.sprin…

洛谷10月月赛Round.1| P3399 丝绸之路 [DP]

题目背景 张骞于公元前138年曾历尽艰险出使过西域。加强了汉朝与西域各国的友好往来。从那以后&#xff0c;一队队骆驼商队在这漫长的商贸大道上行进&#xff0c;他们越过崇山峻岭&#xff0c;将中国的先进技术带向中亚、西亚和欧洲&#xff0c;将那里的香料、良马传进了我国。…

body div js 放大图片_jquery图片放大插件鼠标悬停图片放大效果

都知道jquery都插件是非常强大的&#xff0c;最近分享点jquery插件效果&#xff0c;方便效果开发使用。一、HTML代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> …

MySQL数据库的优化

MySQL数据库的优化 http://www.vpser.net/opt/vps-mysql-opt.html转载于:https://www.cnblogs.com/carbon3/p/5930868.html

我的博客html

我——龙天宇 <table><tr><td width150 align"right"><DIV style"FILTER: Glow(color#4A7AC9,strength50); WIDTH: 149px; HEIGHT: 119px" aligncenter><br><img height89 width119 src"http://img.blog.163.com/p…

预览docx_Windows-快速预览文件-QuickLook

开源、免费的文件快速预览工具&#xff0c; 支持图片、文档、音视频、代码文本、压缩包等多种格式。获得 Mac OS 空格键快速预览文件相同的体验效果图文件夹音视频 浏览压缩包&#xff0c;文本支持的格式&#xff1a;图片&#xff1a;.png, .jpg, .bmp, .gif, .psd, .apng&…

html简单样式

1.外部样式表 link rel"stylesheet" type"text/css" href"bbb.css"> 2.内部样式表 <style type"text/css"> p{ color: bisque; }</style> 3.内联样式表 <a style"color: blueviolet">hhh…

json 微信小程序 筛选_微信小程序学习记录

全局配置app.json 文件用来对微信小程序进行全局配置。pages 类型为 String Array 是 页​面路径列表&#xff0c;创建目录和更改时会自动更改文件。用于指定小程序由哪些页面组成&#xff0c;每一项都对应一个页面的 路径文件名 信息。window 用于设置小程序的状态栏、导航条、…

前端学习(2146):vue中TypeError: this.getResolve is not a function

可能是加载顺序的问题 const path require(path) module.exports {entry: ./src/main.js,output: {path: path.resolve(__dirname, dist),filename: bund.js},module: {rules: [{test: /\.css$/,use: [style-loader, style-loader]}]} }

驱动思想之机制和策略

驱动程序的角色 作为一个程序员, 你能够对你的驱动作出你自己的选择, 并且在所需的编程时间和结果的灵活性之间, 选择一个可接受的平衡. 尽管说一个驱动是"灵活"的, 听起来有些奇怪, 但是我们喜欢这个字眼, 因为它强调了一个驱动程序的角色是提供机制, 而不是策略. 机…

vba 执行网页javascript_JavaScript秘密笔记 第一集

1. 什么是JavaScript2. 如何使用JavaScript3. *变量4. *数据类型谁记得笔记越多&#xff0c;谁学的越烂&#xff01;1. 什么是JavaScript:前端三大语言:HTML: 专门编写网页内容的语言CSS: 专门编写网页样式的语言问题: 使用HTML和CSS做出的网页&#xff0c;只能看不能用——静态…

文字

标题&#xff1a; 标题的大小一共有六种&#xff0c;两个标签一组&#xff0c;也就是从<h1>到<h6>&#xff0c;<h1>最大&#xff0c;<h6>最小。使用标题标签时&#xff0c;该标签会将字体变成粗体字&#xff0c;并且会自成一行。 一般&#xff1a; <…

一定质量的封闭气体被压缩后_多晶硅氯氢化装置补充氢隔膜压缩机十字头铜套磨损原因分析与改善探讨...

潘祝新&#xff0c;王永(江苏中能硅业科技发展有限公司&#xff0c;江苏徐州221004)[摘要]&#xff1a;补充氢气压缩机是多晶硅行业氯氢化装置中的关键设备&#xff0c;它为生产系统的稳定运行不断的补充高纯氢气&#xff0c;其稳定而高效的运行对于生产系统的稳定性及提高氯硅…

vue 生成发布包_年轻人如何从0到1封装发布一个vue组件__Vue.js

封装发布组件是前端开发中非常重要的能力&#xff0c;通过对常用组件的封装可以提升团队开发的效率&#xff0c;避免重复劳作且不方便维护。好的组件的抽象和封装能让组件得到更广泛和多环境兼容的应用。本文讲述了如何一步步从0到1封装发布一个常用的toast组件的过程。本文是搭…