题意:

问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. HTML5开发移动web应用——Sencha Touch篇(7)

    Sencha Touch中的Ext.DomHelper组件能够方便的实现对元素的追加或重写操作 演示样例: launch:function(){ function appendDom(){ Ext.D ...

  2. 【C语言】求两个数中不同的位的个数

    //求两个数中不同的位的个数 #include <stdio.h> int count_different(int a, int b) { int count = 0; int c = a ...

  3. kubernetes之StatefulSet详解

    系列目录 概述 RC.Deployment.DaemonSet都是面向无状态的服务,它们所管理的Pod的IP.名字,启停顺序等都是随机的,而StatefulSet是什么?顾名思义,有状态的集合,管理所 ...

  4. MySQL 存储过程 (2)

    通过存储过程查询数据库返回条数操作 第一步:登录自定义用户建立存储过程需要调用测试用到的student表,具体操作如下 (1) 登录用户

  5. 整形范围 运行Java代码的机器

    Java 无关 C C++ 有关  移植  整形溢出

  6. s1考试 图书管理系统 结构体版

    #include <iostream> #include <string> #include <cstdio> #include <cstdlib> # ...

  7. js 单例模式的实现方式----闭包和构造函数内部判断

    闭包: var singleton = function( fn ){ var result; return function(){ return result || ( result = fn .a ...

  8. Appium——adb 启动问题Invalid argument: cannot open transport registration socketpair could not read ok from ADB Server failed to start daemon * error: cannot connect to daemon

    adb启动问题:Invalid argument: cannot open transport registration socketpair could not read ok from ADB S ...

  9. hadoop 添加,删除节点

    http://www.cnblogs.com/tommyli/p/3418273.html

  10. codeforces 465C.No to Palindromes! 解题报告

    题目链接:http://codeforces.com/problemset/problem/464/A 题目意思:给出一个长度为 n 且是 tolerable 的字符串s,需要求出字典序最小的长度也为 ...