博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 9 E. Thief in a Shop NTT
阅读量:4672 次
发布时间:2019-06-09

本文共 2676 字,大约阅读时间需要 8 分钟。

E. Thief in a Shop
 

A thief made his way to a shop.

As usual he has his lucky knapsack with him. The knapsack can contain k objects. There are n kinds of products in the shop and an infinite number of products of each kind. The cost of one product of kind i is ai.

The thief is greedy, so he will take exactly k products (it's possible for some kinds to take several products of that kind).

Find all the possible total costs of products the thief can nick into his knapsack.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 1000) — the number of kinds of products and the number of products the thief will take.

The second line contains n integers ai (1 ≤ ai ≤ 1000) — the costs of products for kinds from 1 to n.

Output

Print the only line with all the possible total costs of stolen products, separated by a space. The numbers should be printed in the ascending order.

Examples
input
3 2 1 2 3
output
2 3 4 5 6
 
 
题意:
  给你n个数,你可以选数选k次,每次可以选相同的数,问你有多少种和
题解:
  将k分解
  进行log(k)次FFT
  FFT精度可能不够,bool好像能过
  NTT,换一个合适 的 费马素数和原格就能过
   复杂度:O(n*log(n)*log(k))
#include
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")#define ls i<<1#define rs ls | 1#define mid ((ll+rr)>>1)#define pii pair
#define MP make_pairtypedef long long LL;const long long INF = 1e18+1LL;const double pi = acos(-1.0);const int N = 5e5+10, M = 1e3+20,inf = 2e9,mod = 1e9+7;const long long P=23068673LL;const int G=3;LL mul(LL x,LL y){ return (x*y-(LL)(x/(long double)P*y+1e-3)*P+P)%P;}LL qpow(LL x,LL k,LL p){ LL ret=1; while(k){ if(k&1) ret=mul(ret,x); k>>=1; x=mul(x,x); } return ret;}LL wn[50];void getwn(){ for(int i=1; i<=22; ++i){ int t=1<
>1,k; i
>1; while(j>=k){ j-=k; k>>=1; } if(j
>1); ++j){ LL u=y[j],t=mul(y[j+h/2],w); y[j]=u+t; if(y[j]>=P) y[j]-=P; y[j+h/2]=u-t+P; if(y[j+h/2]>=P) y[j+h/2]-=P; w=mul(w,wn[id]); } } } if(op==-1){ for(int i=1; i
0) { if(m%2) { Convolution(now,num); } Convolution(num,num); m/=2; } NTT(now,-1); for(int i = 1; i <= mx; ++i) { if(now[i]) printf("%d ",i); } return 0;}/*3 33 5 11*/

 

转载于:https://www.cnblogs.com/zxhl/p/7106132.html

你可能感兴趣的文章
Python灰帽子pdf
查看>>
Node.js区块链开发pdf
查看>>
轻松学SQL Server数据库pdf
查看>>
Oracle 日期查询
查看>>
说说今年的计划
查看>>
把discuzX 的用户登录信息添加到纯静态页面
查看>>
文件大小计算
查看>>
iOS:给图片置灰色
查看>>
Java 8 (5) Stream 流 - 收集数据
查看>>
ubuntu下安装JDK
查看>>
【C#】使用DWM实现无边框窗体阴影或全透窗体
查看>>
【MySql】脚本备份数据库
查看>>
keil5 配置 stm32f103rc 软件仿真
查看>>
RESTful到底是什么玩意??
查看>>
Oracle创建视图的一个问题
查看>>
(一)线性表
查看>>
hdu 1003 Max Sum (DP)
查看>>
mysql增备
查看>>
[APIO2015]雅加达的摩天楼
查看>>
andorid之帧布局FrameLayout
查看>>