题目传送门

题目大意

没法描述,过于繁杂。

思路

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

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

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

\[\sum_{S1}\sum_{S2}2^{n-\text{pop-count}(S1\oplus S2)}f(S1)f(S2)
\]

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

\(\texttt{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 ('\n');
return 0;
}

CF850E Random Elections 题解的更多相关文章

  1. CF850E Random Elections

    题意:一共有n个人,要在三个人中选prefer,一开始他们心中都会想好他们的排名(共6种),之后给出的判断不会矛盾.规则如下:一共有三轮,分别是a->b,b->c,c->a,每个人选 ...

  2. 【CF850E】Random Elections(FWT)

    [CF850E]Random Elections(FWT) 题面 洛谷 CF 题解 看懂题就是一眼题了... 显然三个人是等价的,所以只需要考虑一个人赢了另外两个人就好了. 那么在赢另外两个人的过程中 ...

  3. 【CF850E】Random Elections FWT

    [CF850E]Random Elections 题意:有n位选民和3位预选者A,B,C,每个选民的投票方案可能是ABC,ACB,BAC...,即一个A,B,C的排列.现在进行三次比较,A-B,B-C ...

  4. CF1043A Elections 题解

    Content 有两个人参加选举,其中已知 \(n\) 位选民投给第二个人的票数为 \(a_1,a_2,a_3,...,a_n\).第一个人很想赢,所以想通过调整每位选民只能投的票数 \(k\) 来让 ...

  5. [Codeforces]850E - Random Elections

    FWT裸题,写了下模板 #include<cstdio> #define ll long long #define r register int #define MN (1<< ...

  6. codeforces850E Random Elections

    题目链接:codeforces 850E 翻译:luogu 读题是第一要务(大选这么随便真的好吗) 其实答案问你的就是在所有选民心中支持的人的所有情况中,能让一个人连赢两场的情况数是多少 我们假设\( ...

  7. CF850 E. Random Elections

    题目传送门:CF 题目大意: 现有\(A,B,C\)三人参加竞选,有n个市民对其进行投票,每个市民心中对三人都有一个优先顺序(如市民\(i\)对三人的优先顺序为\(A-C-B\),则凡是有\(A\)的 ...

  8. CF570A Elections 题解

    Content 有 \(n\) 个候选人和 \(m\) 个城市,每个城市可以给每个候选人投票,已知第 \(i\) 个城市给第 \(j\) 个人投的选票数是 \(a_{i,j}\).我们将第 \(i\) ...

  9. [Leetcode Week17]Copy List with Random Pointer

    Copy List with Random Pointer 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/copy-list-with-random- ...

随机推荐

  1. apt-get 安装程序时报 'E: Unable to locate package xxx' 错误处理办法

    提示无法定位包,要执行命令更新: sudo apt-get update

  2. jquery mobile cdn

    <head> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jque ...

  3. blender Text on Curve Text on Sphere

    Text on Curve Shift + A 添加一个 BezierCurve Shift + A 添加一个 Text,Tab 编辑,再次 Tab 退回 Object Mode 选中 Text,Ad ...

  4. vue 上传头像悬浮显示文字

    template部分: 头像外部加一个 div <div class="user-info-head"> </div>   css 部分 <style ...

  5. IOS 集成 Bilibili IJKPlayer播放器,播放rtmp视频流

    因为公司项目需要,我一个连iPhone都没用过的人竟然跑去开发iOS APP.近一段时间一直忙于赶项目,到今天差不多了,所以记录一下当时遇到的各种坑,先从ios 集成 ijkplayer播放器说起! ...

  6. shell脚本书写

    #!/bin/bash #指定脚本默认使用的命令解释器 第1行 幻数 #!/usr/bin/python #!/bin/awk #!/bin/sed

  7. JDK7&JDK9处理异常新特性

    1.JDK7新特性是在 try (定义对象,作用域就是try方法体) 复制一个文件实例: 复制文件的原理: 先从硬盘写出到内存中,创建文件输入流对象 FileInputStream fis; 中间是在 ...

  8. 清除router路由后面的参数

    清除router参数: 1.this.$router.push({ query: {}}) 2.var path = this.$route.path; //获取路由路径    this.$route ...

  9. el-table回显遇到的坑

    使用element ui 的el-table在做到复选框回显勾中的问题时,整整困惑了我一天,当时百度了一下,好多人都说是  this.$nextTick(() => {})的问提,在组件中监听w ...

  10. FastJson之autotype bypass

    FastJson之autotype bypass 在1.2.25版本之后,添加了checkAutoType方法.在方法中引入了白名单(AutoType).黑名单(denyList)和autoTypeS ...