edu9E. Thief in a Shop
题意:n个物品每个价值a[i],要求选k个,可以重复,问能取到哪几个价值
题解:fft裸题.但是直接一次fft,然后快速幂会boom.这样是严格的\(2^{20}*log2(2^{20})*log(w)\).需要在快速幂里fft,每次取最大的2的次幂,然后fft也boom了,不知道是不是写搓了.ntt过了.....
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 998244353
#define ld long double
//#define C 0.5772156649
//#define ls l,m,rt<<1
//#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}
using namespace std;
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1000000+10,maxn=1000000+10,inf=0x3f3f3f3f;
ll x[N<<3],y[N<<3];
int rev[N<<3];
void getrev(int bit)
{
for(int i=0;i<(1<<bit);i++)
rev[i]=(rev[i>>1]>>1) | ((i&1)<<(bit-1));
}
void ntt(ll *a,int n,int dft)
{
for(int i=0;i<n;i++)
if(i<rev[i])
swap(a[i],a[rev[i]]);
for(int step=1;step<n;step<<=1)
{
ll wn=qp(3,(mod-1)/(step*2));
if(dft==-1)wn=qp(wn,mod-2);
for(int j=0;j<n;j+=step<<1)
{
ll wnk=1;
for(int k=j;k<j+step;k++)
{
ll x=a[k];
ll y=wnk*a[k+step]%mod;
a[k]=(x+y)%mod;a[k+step]=(x-y+mod)%mod;
wnk=wnk*wn%mod;
}
}
}
if(dft==-1)
{
ll inv=qp(n,mod-2);
for(int i=0;i<n;i++)a[i]=a[i]*inv%mod;
}
}
void solve(int k,int p)
{
int sz=0;while((1<<sz)<=p)sz++;sz++;
getrev(sz);
ntt(y,(1<<sz),1);
if(k&1)
{
ntt(x,(1<<sz),1);
for(int i=0;i<(1<<sz);i++)x[i]=x[i]*y[i]%mod;
ntt(x,(1<<sz),-1);
for(int i=0;i<(1<<sz);i++)if(x[i])x[i]=1;
}
for(int i=0;i<(1<<sz);i++)y[i]=y[i]*y[i]%mod;
ntt(y,(1<<sz),-1);
for(int i=0;i<(1<<sz);i++)if(y[i])y[i]=1;
}
int main()
{
int n,k,ma=0;scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
int a;scanf("%d",&a);
y[a]+=1;ma=max(ma,a);
}
x[0]=1;
while(k)solve(k,ma),k>>=1,ma<<=1;
for(int i=1;i<N;i++)if(x[i]!=0)printf("%d ",i);
return 0;
}
/********************
********************/
edu9E. Thief in a Shop的更多相关文章
- 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 ...
- codeforces 632E. Thief in a Shop fft
题目链接 E. Thief in a Shop time limit per test 5 seconds memory limit per test 512 megabytes input stan ...
- C - Thief in a Shop - dp完全背包-FFT生成函数
C - Thief in a Shop 思路 :严格的控制好k的这个数量,这就是个裸完全背包问题.(复杂度最极端会到1e9) 他们随意原来随意组合的方案,与他们都减去 最小的 一个 a[ i ] 组合 ...
- codeforces Educational Codeforces Round 9 E - Thief in a Shop
E - Thief in a Shop 题目大意:给你n ( n <= 1000)个物品每个物品的价值为ai (ai <= 1000),你只能恰好取k个物品,问你能组成哪些价值. 思路:我 ...
- Educational Codeforces Round 9 E. Thief in a Shop dp fft
E. Thief in a Shop 题目连接: http://www.codeforces.com/contest/632/problem/E Description A thief made hi ...
- Educational Codeforces Round 9 E. Thief in a Shop NTT
E. Thief in a Shop A thief made his way to a shop. As usual he has his lucky knapsack with him. Th ...
- CF632E Thief in a Shop 和 CF958F3 Lightsabers (hard)
Thief in a Shop n个物品每个价值ai,要求选k个,可以重复.问能取到哪几个价值? 1 ≤ n, k ≤ 1000,1 ≤ ai ≤ 1000 题解 将选一个物品能取到的价值的01生成函 ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- CF632E: Thief in a Shop(快速幂+NTT)(存疑)
A thief made his way to a shop. As usual he has his lucky knapsack with him. The knapsack can contai ...
随机推荐
- JavaScript之jsx&react
1.Virtual DOM 1.将网页所有内容映射到一颗树形结构的层级对象模型上,浏览器提供对dom的支持,用户可以是用脚本调用dom,api来动态修改dom节点,从而达到修改网页目的,这种修改是浏览 ...
- visualization of filters keras 基于Keras的卷积神经网络(CNN)可视化
https://adeshpande3.github.io/adeshpande3.github.io/ https://blog.csdn.net/weiwei9363/article/detail ...
- 【Spark-SQL学习之二】 SparkSQL DataFrame创建和储存
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk1.8 scala-2.10.4(依赖jdk1.8) spark ...
- Mysql AVG() 值 返回NULL而非空结果集
[1]select 查询返回一行NULL 先来模拟复现一下遇到的问题. (1)源数据表grades,学生成绩表 (2)查询SQL语句 查询‘080601’班的各门课平均成绩 SELECT sClass ...
- httpd 处理模型
prefork 一个请求用一个进程响应 worker 一个请求用一个线程响应(启动多个进程,多个进程生成多个线程) event 一个进程,处理多个请求
- Mysql复制一个数据库到另一个数据库
mysqldump -u root -p source_db > /home/db_bak.sql #导出数据库 123456 #输入数据库密码 扩展: mysqldump -u root -p ...
- 怎么批量删除qq空间说说
1.打开自己的QQ空间 - 说说——右击说说审查元素,打开审查元素.或者直接按f12也可以. 2.在这里我们看到很多分类 3.点击 Console,进入Console项 4.粘贴删除说说的代码,代码为 ...
- Python hasattr() 函数
hasattr() 函数用于判断对象是否包含对应的属性.(has attribute) hasattr(object, name) 参数 object -- 对象. name -- 字符串,属性名. ...
- 面试-java反射
问题:简述Java中的反射使用 答: 1.作用: 可以通过配置文件来动态配置和加载类,以实现软件工程理论里所提及的类与类,模块与模块之间的解耦.反射最经典的应用是spring框架. 2. 定义 反射简 ...
- ORA-19606: Cannot copy or restore to snapshot control file
delete obsolete; 发现出现报错 ORA-19606: Cannot copy or restore to snapshot control file 解决办法:CONFIGURE SN ...