题意:n个物品每个价值a[i],要求选k个,可以重复,问能取到哪几个价值

题解:fft裸题.但是直接一次fft,然后快速幂会boom.这样是严格的\(2^{20}*log2(2^{20})*log(w)\).需要在快速幂里fft,每次取最大的2的次幂,然后fft也boom了,不知道是不是写搓了.ntt过了.....

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. #define fi first
  10. #define se second
  11. #define db double
  12. #define mp make_pair
  13. #define pb push_back
  14. #define pi acos(-1.0)
  15. #define ll long long
  16. #define vi vector<int>
  17. #define mod 998244353
  18. #define ld long double
  19. //#define C 0.5772156649
  20. //#define ls l,m,rt<<1
  21. //#define rs m+1,r,rt<<1|1
  22. #define pll pair<ll,ll>
  23. #define pil pair<int,ll>
  24. #define pli pair<ll,int>
  25. #define pii pair<int,int>
  26. #define ull unsigned long long
  27. //#define base 1000000000000000000
  28. #define fin freopen("a.txt","r",stdin)
  29. #define fout freopen("a.txt","w",stdout)
  30. #define fio ios::sync_with_stdio(false);cin.tie(0)
  31. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  32. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  33. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  34. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  35. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  36. 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;}
  37. 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;}
  38. using namespace std;
  39. const ull ba=233;
  40. const db eps=1e-5;
  41. const ll INF=0x3f3f3f3f3f3f3f3f;
  42. const int N=1000000+10,maxn=1000000+10,inf=0x3f3f3f3f;
  43. ll x[N<<3],y[N<<3];
  44. int rev[N<<3];
  45. void getrev(int bit)
  46. {
  47. for(int i=0;i<(1<<bit);i++)
  48. rev[i]=(rev[i>>1]>>1) | ((i&1)<<(bit-1));
  49. }
  50. void ntt(ll *a,int n,int dft)
  51. {
  52. for(int i=0;i<n;i++)
  53. if(i<rev[i])
  54. swap(a[i],a[rev[i]]);
  55. for(int step=1;step<n;step<<=1)
  56. {
  57. ll wn=qp(3,(mod-1)/(step*2));
  58. if(dft==-1)wn=qp(wn,mod-2);
  59. for(int j=0;j<n;j+=step<<1)
  60. {
  61. ll wnk=1;
  62. for(int k=j;k<j+step;k++)
  63. {
  64. ll x=a[k];
  65. ll y=wnk*a[k+step]%mod;
  66. a[k]=(x+y)%mod;a[k+step]=(x-y+mod)%mod;
  67. wnk=wnk*wn%mod;
  68. }
  69. }
  70. }
  71. if(dft==-1)
  72. {
  73. ll inv=qp(n,mod-2);
  74. for(int i=0;i<n;i++)a[i]=a[i]*inv%mod;
  75. }
  76. }
  77. void solve(int k,int p)
  78. {
  79. int sz=0;while((1<<sz)<=p)sz++;sz++;
  80. getrev(sz);
  81. ntt(y,(1<<sz),1);
  82. if(k&1)
  83. {
  84. ntt(x,(1<<sz),1);
  85. for(int i=0;i<(1<<sz);i++)x[i]=x[i]*y[i]%mod;
  86. ntt(x,(1<<sz),-1);
  87. for(int i=0;i<(1<<sz);i++)if(x[i])x[i]=1;
  88. }
  89. for(int i=0;i<(1<<sz);i++)y[i]=y[i]*y[i]%mod;
  90. ntt(y,(1<<sz),-1);
  91. for(int i=0;i<(1<<sz);i++)if(y[i])y[i]=1;
  92. }
  93. int main()
  94. {
  95. int n,k,ma=0;scanf("%d%d",&n,&k);
  96. for(int i=1;i<=n;i++)
  97. {
  98. int a;scanf("%d",&a);
  99. y[a]+=1;ma=max(ma,a);
  100. }
  101. x[0]=1;
  102. while(k)solve(k,ma),k>>=1,ma<<=1;
  103. for(int i=1;i<N;i++)if(x[i]!=0)printf("%d ",i);
  104. return 0;
  105. }
  106. /********************
  107. ********************/

edu9E. Thief in a 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. 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 ...

  3. C - Thief in a Shop - dp完全背包-FFT生成函数

    C - Thief in a Shop 思路 :严格的控制好k的这个数量,这就是个裸完全背包问题.(复杂度最极端会到1e9) 他们随意原来随意组合的方案,与他们都减去 最小的 一个 a[ i ] 组合 ...

  4. codeforces Educational Codeforces Round 9 E - Thief in a Shop

    E - Thief in a Shop 题目大意:给你n ( n <= 1000)个物品每个物品的价值为ai (ai <= 1000),你只能恰好取k个物品,问你能组成哪些价值. 思路:我 ...

  5. 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 ...

  6. 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 ...

  7. CF632E Thief in a Shop 和 CF958F3 Lightsabers (hard)

    Thief in a Shop n个物品每个价值ai,要求选k个,可以重复.问能取到哪几个价值? 1 ≤ n, k ≤ 1000,1 ≤ ai ≤ 1000 题解 将选一个物品能取到的价值的01生成函 ...

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

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

  9. 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 ...

随机推荐

  1. JavaScript之jsx&react

    1.Virtual DOM 1.将网页所有内容映射到一颗树形结构的层级对象模型上,浏览器提供对dom的支持,用户可以是用脚本调用dom,api来动态修改dom节点,从而达到修改网页目的,这种修改是浏览 ...

  2. visualization of filters keras 基于Keras的卷积神经网络(CNN)可视化

    https://adeshpande3.github.io/adeshpande3.github.io/ https://blog.csdn.net/weiwei9363/article/detail ...

  3. 【Spark-SQL学习之二】 SparkSQL DataFrame创建和储存

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk1.8 scala-2.10.4(依赖jdk1.8) spark ...

  4. Mysql AVG() 值 返回NULL而非空结果集

    [1]select 查询返回一行NULL 先来模拟复现一下遇到的问题. (1)源数据表grades,学生成绩表 (2)查询SQL语句 查询‘080601’班的各门课平均成绩 SELECT sClass ...

  5. httpd 处理模型

    prefork 一个请求用一个进程响应 worker 一个请求用一个线程响应(启动多个进程,多个进程生成多个线程) event 一个进程,处理多个请求

  6. Mysql复制一个数据库到另一个数据库

    mysqldump -u root -p source_db > /home/db_bak.sql #导出数据库 123456 #输入数据库密码 扩展: mysqldump -u root -p ...

  7. 怎么批量删除qq空间说说

    1.打开自己的QQ空间 - 说说——右击说说审查元素,打开审查元素.或者直接按f12也可以. 2.在这里我们看到很多分类 3.点击 Console,进入Console项 4.粘贴删除说说的代码,代码为 ...

  8. Python hasattr() 函数

    hasattr() 函数用于判断对象是否包含对应的属性.(has attribute) hasattr(object, name) 参数 object -- 对象. name -- 字符串,属性名. ...

  9. 面试-java反射

    问题:简述Java中的反射使用 答: 1.作用: 可以通过配置文件来动态配置和加载类,以实现软件工程理论里所提及的类与类,模块与模块之间的解耦.反射最经典的应用是spring框架. 2. 定义 反射简 ...

  10. ORA-19606: Cannot copy or restore to snapshot control file

    delete obsolete; 发现出现报错 ORA-19606: Cannot copy or restore to snapshot control file 解决办法:CONFIGURE SN ...