zoukankan      html  css  js  c++  java
  • CF850E Random Elections 题解

    题目传送门

    题目大意

    没法描述,过于繁杂。

    思路

    果然自己是个菜鸡,只能靠读题解读题,难受极了,其实不是很难自己应该做得出来的。。。。哎。。。。

    不难发现可以统计 (A) 获胜的情况乘上 (3) 就是总答案。然后 (A) 获胜的情况其实就是满足 (f(S1)=f(S2)=1) 乘上满足是 (S1S2) 的方案数。然后看后面那个东西,你发现对于人 (i) 如果 (S1_i=1wedge S2_i=1) 的话有 (2) 中情况,就是 ( ext{BCA,CBA}) ,如果 (S1_i=0wedge S2_i=1) 的话有 (1) 种情况,就是 ( ext{BAC}) ,另外两种类似。然后你就发现如果 (S1_i=S2_i) 贡献就是 (2) ,反之为 (1)

    整理一下,发现答案其实就是:

    [sum_{S1}sum_{S2}2^{n- ext{pop-count}(S1oplus S2)}f(S1)f(S2) ]

    然后你就发现这个东西可以使用 ( exttt{FWT}) 进行优化。时间复杂度就变为了 (Theta(2^n n))

    ( exttt{Code})

    #include <bits/stdc++.h>
    using namespace std;
    
    #define Int register int
    #define mod 1000000007
    #define MAXN 1048576
    
    int n,g[MAXN],pw[25],cnt[MAXN];
    
    void FWT (int *f,int type){
    	for (Int i = 1;i < n;i <<= 1)
    		for (Int j = 0;j < n;j += i << 1)
    			for (Int k = 0;k < i;++ k){
    				int x = f[j + k],y = f[i + j + k];
    				f[j + k] = 1ll * type * (x + y) % mod,
    				f[i + j + k] = 1ll * type * (x + mod - y) % mod;
    			}
    } 
    
    template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
    template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
    template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
    
    signed main(){
    	read (n);
    	pw[n] = 1;for (Int i = n - 1;~i;-- i) pw[i] = pw[i + 1] * 2;n = 1 << n;
    	for (Int i = 0;i < n;++ i) scanf ("%1d",&g[i]),cnt[i] = cnt[i >> 1] + (i & 1);
    	FWT (g,1);for (Int i = 0;i < n;++ i) g[i] = 1ll * g[i] * g[i] % mod;FWT (g,(mod + 1) >> 1);
    	int ans = 0;for (Int i = 0;i < n;++ i) ans = (ans + 1ll * g[i] * pw[cnt[i]] % mod) % mod;
    	write (ans * 3ll % mod),putchar ('
    ');
    	return 0;
    }
    
  • 相关阅读:
    JVM学习笔记-指向Class类的引用(A Reference to Class Class)
    JVM学习笔记-方法区示例与常量池解析(Method Area Use And Constant Pool Resolution)
    JVM学习笔记-堆(Heap)
    JVM学习笔记-程序计数器(The Program Counter)
    JVM学习笔记-栈(Stack)
    JVM学习笔记-栈帧(The Stack Frame)
    JVM学习笔记-局部变量区(Local Variables)
    html大文件传输源代码
    html大文件传输源码
    html大文件传输插件
  • 原文地址:https://www.cnblogs.com/Dark-Romance/p/13545359.html
Copyright © 2011-2022 走看看