from NOIP2016模拟题36

Description

商店里有n种背包和m种物品,物品体积为1到m,背包容积<=m

给出n个背包的容积

现在要求出这样一个物品集合,满足:

1)对于任意一个背包,都能找到这样一个物品的子集,使得这个子集中物品的体积和(每个物品可以使用多次)恰好等于背包的容积

2)对于每一个体积和小于等于m的物品子集(每个物品可以使用多次),都有一个背包容积恰好等于这个体积和

求满足条件的最少的物品集合

Analysis

有解 \(\Leftrightarrow\) 物品集=背包体积集合 时 有解

然后我们要缩小集合

就是判断一个数能不能被小于它的数背包dp出来

然而由于题目的特殊性质

只用是否存在两个小于它的数a,b满足a+b等于它

我们可以用FFT

简单证明:

若已经求出有解

a,b,c,d在物品集中

则2a,3a.....都在物品集中

同理a+b,2a+b,4a+2b+3c,2a+4b+5c+d什么的都在集合中

集合中的数任意两个相加即可表示任何数

证完了

回到一开始怎么知道物品集=背包集的情况是否满足条件?

将物品集conv后看看是否出现新数

有就不满足

Code

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
using namespace std;
const double pi=acos(-1.0);
const int M=1000007;
const int N=2097152; inline int rd(){
int x=0;bool f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
for(;isdigit(c);c=getchar()) x=x*10+c-48;
return f?x:-x;
} int n,m;
int rev[N];
struct CP{
double x,i;
CP(double xx=0.0,double ii=0.0){x=xx;i=ii;}
}a[N];
CP operator +(CP x,CP y){return CP(x.x+y.x,x.i+y.i);}
CP operator -(CP x,CP y){return CP(x.x-y.x,x.i-y.i);}
CP operator *(CP x,CP y){return CP(x.x*y.x-x.i*y.i,x.i*y.x+x.x*y.i);} void FFT(CP *a,int fl){
int i,j,k;
CP W,Wn,u,v;
for(i=0;i<N;i++) if(rev[i]<i) swap(a[i],a[rev[i]]); for(i=2;i<=N;i<<=1){
Wn=CP(cos(2*pi/i),fl*sin(2*pi/i));
for(j=0;j<N;j+=i){
W=CP(1,0);
for(k=j;k<j+i/2;k++,W=W*Wn){
u=a[k];
v=W*a[k+i/2];
a[k]=u+v;
a[k+i/2]=u-v;
}
}
} if(fl==-1)
for(i=0;i<N;i++) a[i].x=(a[i].x/N)+0.5;
} int vis[M];
int ans=0; int main(){
int i,j,k,x;
n=rd(),m=rd();
for(i=1;i<=n;i++){
x=rd();
vis[x]=1;
a[x]=CP(1,0);
} for(i=0;i<N;i++) rev[i]=(rev[i>>1]>>1)|((i&1)?(N>>1):0);
FFT(a,1);
for(i=0;i<N;i++) a[i]=a[i]*a[i];
FFT(a,-1); ans=n;
for(i=1;i<=m;i++)
if(a[i].x>=1){ //注意现在是double
if(!vis[i]){
puts("NO");
return 0;
}
ans--;
} puts("YES");
printf("%d\n",ans);
for(i=1;i<=m;i++)
if(vis[i]&&a[i].x<1){
if(ans>1) printf("%d ",i);
else printf("%d\n",i);
ans--;
}
return 0;
}

xsy 1836 - Shop的更多相关文章

  1. codeforces 632+ E. Thief in a Shop

    E. Thief in a Shop time limit per test 5 seconds memory limit per test 512 megabytes input standard ...

  2. Codeforces632E Thief in a Shop(NTT + 快速幂)

    题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...

  3. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

  4. Magicodes.Shop——版本历史

    Magicodes.Shop为湖南心莱信息科技有限公司(xin-lai.com)Magicodes系列产品之一. 产品中引用的Magicodes系列Nuget包的开源库地址为:https://gith ...

  5. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  6. PHP Yii1.1.13(一):命令行创建应用~shop

    第一节 初始目录结构 (1)初识目录结构 在创建应用之前,我们来看一下Yii 1.x版本的目录结构:将yii-1.1.13安装文件解压到网站根目录下,打开framework目录,其目录如下图所示 (2 ...

  7. [POJ1157]LITTLE SHOP OF FLOWERS

    [POJ1157]LITTLE SHOP OF FLOWERS 试题描述 You want to arrange the window of your flower shop in a most pl ...

  8. LITTLE SHOP OF FLOWERS_DP

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20802   Accepted: 9613 Description You ...

  9. HDU 4884 TIANKENG’s rice shop (模拟)

    TIANKENG's rice shop 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/J Description TIANKE ...

随机推荐

  1. 安装mysqlclient失败

    环境:python3.6 sudo apt-get install python3.6-dev sudo apt-get install default-libmysqlclient-dev 参考:h ...

  2. 2018 noip 提高组初赛参考答案

    这里有pdf文件:戳这儿

  3. NOIP模拟赛 虫洞

    [题目描述] John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N (从1. ...

  4. 【linux】服务说明

     引用自<鸟哥的linux私房菜>  http://cn.linux.vbird.org/linux_server/0210network-secure_3.php 服务名称 服务内容 a ...

  5. VS自学日记整理

    vs渣渣自学之旅 一.vs实用插件 二.制作简历之旅 1.一堆错误示范示范 2.标签的使用 3.文件的文本的样式的保存 二.美化博客园之旅 1.第一天 学python有点多这个慢慢消化

  6. ubuntu 16.04下如何打造 sublime python编程环境

    一.安装python3     ubuntu自身是安装python2的,例如在ubuntu 16.04中安装的就是python2.7.但我想在python3的环境下进行开发所以就要安装python3. ...

  7. 掌握这些Python代码技巧,编程至少快一半!

    被人工智能捧红的 Python 已是一种发展完善且非常多样化的语言,其中肯定有一些你尚未发现的功能.本文或许能够让你学到一些新技巧. ​ Python 是世界上最流行.热门的编程语言之一,原因很多,比 ...

  8. LeetCode(165) Compare Version Numbers

    题目 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version ...

  9. LeetCode(260) Single Number III

    题目 Given an array of numbers nums, in which exactly two elements appear only once and all the other ...

  10. Aizu 2450 Do use segment tree 树链剖分

    题意: 给出一棵\(n(1 \leq n \leq 200000)\)个节点的树,每个节点有一个权值. 然后有\(2\)种操作: \(1 \, a \, b \, c\):将路径\(a \to b\) ...