UOJ310. 銆怳NR #2銆戦粠鏄庡墠鐨勫阀鍏嬪姏 [FWT]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UOJ310. 銆怳NR #2銆戦粠鏄庡墠鐨勫阀鍏嬪姏 [FWT]相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%9c%b4%e7%b4%a0' title='鏈寸礌'>鏈寸礌   mes   pair   long   line   span   琛ㄧず   ||   register   

UOJ

鎬濊矾

鏄剧劧鍙互杞寲涓€涓嬶紝鍙樻垚缁熻寮傛垨璧锋潵绛変簬0鐨勯泦鍚堜釜鏁帮紝杩欐牱涓€涓泦鍚堢殑璐$尞鏄?span class="math inline">\(2^|S|\)銆?/p>

鑰冭檻鏈寸礌鐨?span class="math inline">\(dp_i,j\)琛ㄧず鍓?span class="math inline">\(i\)涓暟鍑戝嚭浜?span class="math inline">\(j\)鐨勬柟妗堟暟锛屽彂鐜拌繖鍏跺疄灏辨槸涓€鍫嗗椤瑰紡鐢ㄥ紓鎴栧嵎绉悶璧锋潵銆傜\(i\)涓椤瑰紡鏄?span class="math inline">\(1+2x^a_i\)銆?/p>

瀵?span class="math inline">\(1+2x^a\)FWT涓€涓嬶紝鍙戠幇缁撴灉灏卞彧鏈?code>-1鍜?code>3銆備负浠€涔堬紵鏍规嵁FWT鐨勭悊璁猴紝\(a_i\)浼氬\(FWT(a)_j\)浜х敓\(a_i\times (-1)^\textbitcnt[i\&j]\)鐨勮础鐚€?/p>

鎴戜滑灏辨槸瑕佹眰鍑烘渶鍚庤繖涓€鍫嗕笢瑗夸箻鍦ㄤ竴璧锋槸浠€涔堬紝涔熷氨鏄浜庢瘡涓€浣嶆眰鍑鸿繖閲屾湁鍑犱釜-1锛屾湁鍑犱釜3銆?/p>

杩欎釜鎬庝箞鍋氾紵鑴戞礊涓€涓嬶紝鎶婃墍鏈夊椤瑰紡鍔犲湪涓€璧稦WT锛岃鏈?span class="math inline">\(x\)涓?1锛岄偅涔堝氨鏈夋柟绋?span class="math inline">\(-x+3(n-x)=f_i\)锛屽氨鍙互瑙e嚭鏉ヤ簡銆?/p>

鏈€鍚庡啀FWT鍥炲幓锛屽氨鍋氬畬浜嗐€?/p>

锛堣繖涓В鏂圭▼鍜嬫兂鍒扮殑鍟妐wq锛?/p>

浠g爜

鏈€鍚庡噺1涓嶅彇妯′綘浜哄氨娌′簡qwq

#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    #define sz 1100000
    #define mod 998244353ll
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) return uniform_int_distribution<T>(l,r)(rng);
    templ inline bool chkmax(T &x,T y)return x<y?x=y,1:0;
    templ inline bool chkmin(T &x,T y)return x>y?x=y,1:0;
    templ inline void read(T& t)
    
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.')ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();
        t=(f?-t:t);
    
    template<typename T,typename... Args>inline void read(T& t,Args&... args)read(t); read(args...);
    char __sr[1<<21],__z[20];int __C=-1,__zz=0;
    inline void Ot()fwrite(__sr,1,__C+1,stdout),__C=-1;
    inline void print(register int x)
    
        if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
        while(__z[++__zz]=x%10+48,x/=10);
        while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
    
    void file()
    
        #ifdef NTFOrz
        freopen("a.in","r",stdin);
        #endif
    
    inline void chktime()
    
        #ifndef ONLINE_JUDGE
        cout<<(clock()-t)/1000.0<<'\n';
        #endif
    
    #ifdef mod
    ll ksm(ll x,int y)ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;
    ll inv(ll x)return ksm(x,mod-2);
    #else
    ll ksm(ll x,int y)ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;
    #endif
//  inline ll mul(ll a,ll b)ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;

using namespace my_std;

int n;
int a[sz];

int f[sz];
ll g[sz];
void FWT(int *a,int n)

    int N=1<<n,x,y;
    rep(i,0,n-1)
        for (int mid=1<<i,j=0;j<N;j+=mid<<1)
            rep(k,0,mid-1)
                x=a[j+k],y=a[j+k+mid],a[j+k]=x+y,a[j+k+mid]=x-y;

ll I=inv(2);
void iFWT(ll *a,int n)

    int N=1<<n;ll x,y;
    rep(i,0,n-1)
        for (int mid=1<<i,j=0;j<N;j+=mid<<1)
            rep(k,0,mid-1)
                x=a[j+k],y=a[j+k+mid],a[j+k]=(x+y)*I%mod,a[j+k+mid]=(x-y+mod)*I%mod;


int main()

    file();
    read(n);
    rep(i,1,n) read(a[i]),++f[0],f[a[i]]+=2;
    FWT(f,20);
    int x;
    rep(i,0,(1<<20)-1) x=(3*n-f[i])/4,g[i]=ksm(mod-1,x)*ksm(3,n-x)%mod;
    iFWT(g,20);
    printf("%lld\n",(g[0]-1+mod)%mod);
    return 0;

以上是关于UOJ310. 銆怳NR #2銆戦粠鏄庡墠鐨勫阀鍏嬪姏 [FWT]的主要内容,如果未能解决你的问题,请参考以下文章

@uoj - 310@ UNR #2黎明前的巧克力

uoj310. UNR #2黎明前的巧克力

uoj#310. UNR #2黎明前的巧克力

[UOJ310][UNR #2]黎明前的巧克力

UOJ 310 黎明前的巧克力(FWT)

uoj310[UNR #2]黎明前的巧克力 FWT