E. Ladies' Shop
time limit per test

8 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A ladies' shop has recently opened in the city of Ultima Thule. To get ready for the opening, the shop bought n bags. Each bag is characterised by the total weight ai of the items you can put there. The weird thing is, you cannot use these bags to put a set of items with the total weight strictly less than ai. However the weights of the items that will be sold in the shop haven't yet been defined. That's what you should determine right now.

Your task is to find the set of the items' weights p1, p2, ..., pk (1 ≤ p1 < p2 < ... < pk), such that:

  1. Any bag will be used. That is, for any i (1 ≤ i ≤ n) there will be such set of items that their total weight will equal ai. We assume that there is the infinite number of items of any weight. You can put multiple items of the same weight in one bag.
  2. For any set of items that have total weight less than or equal to m, there is a bag into which you can put this set. Similarly, a set of items can contain multiple items of the same weight.
  3. Of all sets of the items' weights that satisfy points 1 and 2, find the set with the minimum number of weights. In other words, value k should be as small as possible.

Find and print the required set.

Input

The first line contains space-separated integers n and m (1 ≤ n, m ≤ 106). The second line contains ndistinct space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ m) — the bags' weight limits.

Output

In the first line print "NO" (without the quotes) if there isn't set pi, that would meet the conditions.

Otherwise, in the first line print "YES" (without the quotes), in the second line print an integer k (showing how many numbers are in the suitable set with the minimum number of weights), in the third line print kspace-separated integers p1, p2, ..., pk (1 ≤ p1 < p2 < ... < pk). If there are multiple solutions, print any of them.

Examples
input
6 10
5 6 7 8 9 10
output
YES
5
5 6 7 8 9
input
1 10
1
output
NO
input
1 10
6
output
YES
1
6

——————————————————————————

然后来谈谈这道题了

题面是给n个篮子,要求制造不限制数目的商品,要求这些商品任意组合(可重复)的和在<m时总能找到一个容量等于和的篮子

有解输出YES,个数,商品的值,多组解要求输出篮子数最少,没有输出NO

首先按照题意来说我们随便组合这些商品,获得的值都有一个篮子来装

那么如果我们按每个篮子的值制造一种商品,每个篮子的值都可以由一个原商品,或两个原商品得到

为什么不是三个或以上,建设是三个组成这个篮子值A的话其中两个组成的商品会有一个篮子B来装,按照我们的条件,这个篮子值B的商品已经被制造出来了,所以假设不成立

也就是这样——

(栗子)

n=3 m=3

篮子:1 2 3

我们制造出的商品:1 2 3

我们发现1 1 1可以填满容量为3的篮子

但是1 1组合是2 ,我们已经制造出了2

可以是3=1+2,当然也有3=3

这个说明我们只要这样制造商品,每个商品和所有商品(包括自身)重新组合,就可以得到所有m以内商品和的种类 ——

(例子)

n=3 m=6(修改m)

篮子:1 2 3

我们制造出的商品:1 2 3

可搭配出

1+1=2 1+2=3 1+3=4

2+1=3 2+2=4 2+3=5

3+1=4 3+2=5 3+3=6

我们通过这些值可以判断,创造出的4 5 6无法装下,所以是NO

如果m=3

n=3 m=3

篮子:1 2 3

我们制造出的商品:1 2 3

可搭配出

1+1=2 1+2=3 1+3=4

2+1=3 2+2=4 2+3=5

3+1=4 3+2=5 3+3=6

我们发现2 3能被重新组合出来所以我们贪心地删除2 3 答案就是1

2用来构建3的,怎么被删除了呢

如果2被删除,说明2也可以被构建,故删除

所以根据xa*xb=xa+b

我们可以根据(xa1*xa2...xan)2来判断两两组合的所有解,满足卷积,所以FFT

【两个版本的FFT↓】

 #include <cmath>
#include <iostream>
#include <cstdio>
#include <cstring>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
typedef long long ll;
const double PI=3.14159265358979323;//似乎精度要大大大大大大大
using namespace std;
struct complex {
double r,i;
complex(double real=0.0,double image=0.0) {
r=real;i=image;
}
complex operator + (const complex &a)const {
return complex(r+a.r,i+a.i);
}
complex operator - (const complex &a)const {
return complex(r-a.r,i-a.i);
}
complex operator * (const complex &a) const{
return complex(r*a.r-i*a.i,r*a.i+i*a.r);
}
}num1[],num2[];
void brc(complex *p,int l) {
int j=l/;
for(int i=;i<l-;++i) {//l-1是因为如果最后减完k=0,j=0
if(i<j) swap(p[i],p[j]);
int k=l/;
while(j>=k) {
j-=k;
k>>=;
}
if(j<k) j+=k;
}
}
//迭代版
void FFT(complex *p,int l,double flag) {
brc(p,l);
complex u,t;
for(int h=;h<=l;h<<=) {
complex wn(cos(flag**PI/h),sin(flag**PI/h));
for(int k=;k<l;k+=h){
complex w(,);
for(int j=k;j<k+h/;++j) {
u=p[j];
t=w*p[j+h/];
p[j]=u+t;
p[j+h/]=u-t;
w=w*wn;
}
}
}
}
//递归版
/*complex tmp[505];
void FFT(complex *p,int dep,int l,double flag) {
if((1<<dep)==l) return;
int step=1<<dep;
FFT(p,dep+1,l,flag);
FFT(p+step,dep+1,l,flag);
int newlen=l>>dep,half=newlen>>1;
complex wn(cos(2*flag*PI/newlen),sin(2*flag*PI/newlen));
complex w(1,0);
for(int i=0,s=0;i<half;++i,s+=(step<<1)) {
complex a=p[s];
complex b=w*p[s+step];
tmp[i]=a+b;
tmp[i+half]=a-b;
w=w*wn;
}
for(int i=0;i<newlen;++i) {
p[i<<dep]=tmp[i];
}
}//IDFT要除l*/
bool ok;
int a,b[],ans[],ac[],cnt;
int n,m;
void solve() {
scanf("%d%d",&n,&m);
int l=;
memset(b,,sizeof(b));
siji(i,,n) {
scanf("%d",&a);
b[a]=;
}
while(l<*m) {l=l<<;}
xiaosiji(i,,m) {
num1[i]=complex((double)b[i],0.0); }
FFT(num1,l,);
xiaosiji(i,,l) {
num2[i]=num1[i];
}
xiaosiji(i,,l) {
num1[i]=num1[i]*num2[i];
}
FFT(num1,l,-);
for(int z=;z<l;++z) num1[z].r/=l;
ok=true;
siji(i,,m) {
ans[i]=(int)(num1[i].r+0.5);
}
//为什么我这个sb写了个进位??????
//明明这不是大整数乘法啊QAQ
siji(i,,m) {
if(ans[i]>) {
if(b[i]==) {b[i]=;}
else if(b[i]==) {ok=;}
}
}
if(ok) {
puts("YES");
siji(i,,m) {
if(b[i]>) ac[++cnt]=i;
}
printf("%d\n",cnt);
siji(i,,cnt) {
printf("%d%c",ac[i]," \n"[i==cnt]);
}
}
else{
puts("NO");
}
}
int main(int argc, char const *argv[])
{
//freopen("f1.in","r",stdin);
solve();
return ;
}

codeforces 286 E. Ladies' Shop (FFT)的更多相关文章

  1. Codeforces 286E - Ladies' Shop(FFT)

    Codeforces 题面传送门 & 洛谷题面传送门 好久没刷过 FFT/NTT 的题了,写篇题解罢( 首先考虑什么样的集合 \(T\) 符合条件.我们考察一个 \(x\in S\),根据题意 ...

  2. 快速傅里叶(FFT)的快速深度思考

    关于按时间抽取快速傅里叶(FFT)的快速理论深度思考 对于FFT基本理论参考维基百科或百度百科. 首先谈谈FFT的快速何来?大家都知道FFT是对DFT的改进变换而来,那么它究竟怎样改进,它改进的思想在 ...

  3. 【BZOJ3527】力(FFT)

    [BZOJ3527]力(FFT) 题面 Description 给出n个数qi,给出Fj的定义如下: \[Fj=\sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{ ...

  4. 【BZOJ4827】【HNOI2017】礼物(FFT)

    [BZOJ4827][HNOI2017]礼物(FFT) 题面 Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每 ...

  5. FFT/NTT总结+洛谷P3803 【模板】多项式乘法(FFT)(FFT/NTT)

    前言 众所周知,这两个东西都是用来算多项式乘法的. 对于这种常人思维难以理解的东西,就少些理解,多背板子吧! 因此只总结一下思路和代码,什么概念和推式子就靠巨佬们吧 推荐自为风月马前卒巨佬的概念和定理 ...

  6. 【BZOJ4503】两个串(FFT)

    [BZOJ4503]两个串(FFT) 题面 给定串\(S\),以及带通配符的串\(T\),询问\(T\)在\(S\)中出现了几次.并且输出对应的位置. \(|S|,|T|<=10^5\),字符集 ...

  7. 【BZOJ4259】残缺的字符串(FFT)

    [BZOJ4259]残缺的字符串(FFT) 题面 给定两个字符串\(|S|,|T|\),两个字符串中都带有通配符. 回答\(T\)在\(S\)中出现的次数. \(|T|,|S|<=300000\ ...

  8. 【51Nod1258】序列求和V4(FFT)

    [51Nod1258]序列求和V4(FFT) 题面 51Nod 多组数据,求: \[Ans=\sum_{i=1}^ni^k,n\le 10^{18},k\le50000\] 题解 预处理伯努利数,时间 ...

  9. 【CF528D】Fuzzy Search(FFT)

    [CF528D]Fuzzy Search(FFT) 题面 给定两个只含有\(A,T,G,C\)的\(DNA\)序列 定义一个字符\(c\)可以被匹配为:它对齐的字符,在距离\(K\)以内,存在一个字符 ...

随机推荐

  1. 很受欢迎的vue前端UI框架

    最近在逛各大网站,论坛,SegmentFault等编程问答社区,发现Vue.js异常火爆,重复性的提问和内容也很多,小编自己也趁着这个大前端的热潮,着手学习了一段时间的Vue.js,目前用它正在做自己 ...

  2. Javascript 浮点计算问题分析与解决

    分析 JavaScript 只有一种数字类型 Number ,而且在Javascript中所有的数字都是以IEEE-754标准格式表示的. 浮点数的精度问题不是JavaScript特有的,因为有些小数 ...

  3. weUI框架在github下载地址

    1.公众号样式UI库的下载地址: https://github.com/Tencent/weui 2.微信小程序UI库的下载地址:https://github.com/Tencent/weui-wxs ...

  4. ICDM Winner's Interview: 3rd place, Roberto Diaz

    ICDM Winner's Interview: 3rd place, Roberto Diaz This summer, the ICDM 2015 conference sponsored a c ...

  5. Mac下MySQL的卸载

    先停止所有mysql有关进程. 打开控制台一次复制下列所有内容: sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm -rf ...

  6. python 12306 车次数据获取

    ssl._create_default_https_context = ssl._create_default_https_context train_data = '2018-10-20' head ...

  7. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  8. Mysql 关闭自动commit

    更多内容推荐微信公众号,欢迎关注: 1. 会话级关闭自动提交 mysql> set autocommit=off; Query OK, 0 rows affected (0.00 sec) my ...

  9. [转]Laplace算子和Laplacian矩阵

    1 Laplace算子的物理意义 Laplace算子的定义为梯度的散度. 在Cartesian坐标系下也可表示为: 或者,它是Hessian矩阵的迹: 以热传导方程为例,因为热流与温度的梯度成正比,那 ...

  10. jQuery动态给下拉列表添加一个选项(创建DOM对象)

    使用的函数: