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;
}
/********************

********************/
上一篇:Vue_shop项目


下一篇:IDEA创建三级父子模块Maven项目(Springboot)(一)----项目构建