题意:

问n个物品选出K个可以拼成的体积有哪些。

解法:

多项式裸题,注意到本题中 $A(x)^K$ 的系数会非常大,采用NTT优于FFT。

NTT 采用两个 $2^t+1$ 质数,求原根 $g_n$ 后用 $g_n^1 $~$ g_n^{P-1}$ 的循环代替复数向量的旋转。

注意逆的 $w_n$ 是 $g_n ^ {  - \frac{P-1}{len}  }$,并且要用两个质数保证正确即可,$O(nlogn)$。

#include <bits/stdc++.h>

#define PI acos(-1)
#define P1 998244353LL
#define P2 469762049LL
#define LL long long
#define gn 3 const int N = ; using namespace std; int R[N<<]; LL qpow(LL x,int n,LL P)
{
LL ans = ;
for(;n;n>>=,x = x*x % P) if(n&) ans = ans*x % P;
return ans;
} void DFT(LL a[],int n,int tp_k,LL P)
{
for(int i=;i<n;i++) if(i<R[i]) swap(a[i],a[R[i]]);
for(int d=;d<n;d<<=)
{
LL wn = qpow(gn, (P-)/(d<<),P);
if(tp_k == -) wn = qpow(wn, P-,P);
for(int i=;i<n;i += (d<<))
{
LL wt = ;
for(int k=;k<d;k++, wt = wt*wn % P)
{
LL A0 = a[i+k], A1 = wt * a[i+k+d] % P;
a[i+k] = A0+A1;
a[i+k+d] = A0+P-A1;
if(a[i+k] >= P) a[i+k] -= P;
if(a[i+k+d] >= P) a[i+k+d] -= P;
}
}
}
LL inv = qpow(n, P-,P);
if(tp_k==-)
for(int i=;i<n;i++) a[i] = a[i] * inv % P;
} LL A[N<<],B[N<<]; int main()
{
//freopen("test.txt","w",stdout);
int n,K;
cin>>n>>K;
int L = ,tot;
while((<<L)<*K) L++;
tot = (<<L);
for(int i=;i<tot;i++) R[i]=(R[i>>]>>)|((i&)<<(L-));
for(int i=,x;i<=n;i++) scanf("%d",&x), A[x] = , B[x] = ;
DFT(A,tot,,P1);
for(int i=;i<tot;i++) A[i] = qpow(A[i], K, P1);
DFT(A,tot,-,P1);
DFT(B,tot,,P2);
for(int i=;i<tot;i++) B[i] = qpow(B[i], K, P2);
DFT(B,tot,-,P2);
for(int i=;i<tot;i++) if(A[i] || B[i]) printf("%d ",i);
printf("\n");
return ;
}

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

  10. codeforces632E. Thief in a Shop (dp)

    A thief made his way to a shop. As usual he has his lucky knapsack with him. The knapsack can contai ...

随机推荐

  1. Laravel 5.4建站06--API 认证系统 Passport

    介绍 在 Laravel 中,实现基于传统表单的登陆和授权已经非常简单,但是如何满足 API 场景下的授权需求呢?在 API 场景里通常通过令牌来实现用户授权,而非维护请求之间的 Session 状态 ...

  2. IDEA搭建Android wear开发环境,Android wear,I&#39;m comming!

    随着google公布了android wear这个东西.然后又有了三星的gear,LG的G watch以及moto 360,苹果由公布了apple watch.未来可能在智能手表行业又有一场战争. 当 ...

  3. MVC3-表单

    [.NET Core已取消]Html.BeginForm() 该方法用于构建一个From表单的开始,他的构造方法为:Html.BeginForm("ActionName", &qu ...

  4. vue directive demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. ASP.NET页面之间传值的几种方式

    1.  QueryString 当页面上的form以get方式向页面发送请求数据时,web server将请求数据放入一名为QEURY_STRING的环境变量中,QeueryString方法从这个变量 ...

  6. inline-block的使用

    inline-block是什么 inline和block是css中元素display属性的两个选项,而inline-block可以说是介于两者之间的属性值. inline使元素成为内联元素(inlin ...

  7. MVC5中使用jQuery Post 二维数组和一维数组到Action

    很久没有写了,最近在做一个MVC项目,这是我做的第一个MVC项目.之前可以说多MVC一点都不了解,今天把昨天遇到的一个问题记录下来.MVC大神就请飘过吧,跟我遇到同样问题的可以进来看看.遇到的第一个问 ...

  8. LeetCode(16)题解--3Sum Closest

    https://leetcode.com/problems/3sum-closest/ 题目: Given an array S of n integers, find three integers ...

  9. 在html中显示Flash的代码

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...

  10. EasyPlayer安卓Android流媒体播放器实现直播过程中客户端快照功能

    本文转自:http://blog.csdn.net/jyt0551/article/details/56942795 对于一个裸的RTSP URL,存放在播放列表上略显单调与枯燥.大家可以看到Easy ...