Atcoder CF 2017 TR I

给定一个有n个点,m条边的图,求为每条边定向,使得从1出发和2出发的两个人可以见面的方案数。

先把问题转换成求all-不能见面的方案数。那么可以把图划分成这样一个集合:

用\(f[0/1][i]\)表示包含0/1的集合i,从0/1出发刚好能到达所有点的方案数 。注意是“刚好“,所以统计的是闭合子图。利用容斥原理求出f,接下来的任务就是统计other集合中,与两个集合不相关的边的个数即可。

#include <cstdio>
using namespace std; const int maxn=20, maxm=120, maxs=4e4, p=1e9+7;
int n, m, a[maxm], b[maxm], c[maxs], d[maxs], mi2[maxm];
long long f[2][maxs], ans;
//f[0/1][i]表示包含0/1的集合i,从0/1出发刚好能到达所有点的方案数 int main(){
scanf("%d%d", &n, &m);
for (int i=mi2[0]=1; i<maxm; ++i)
mi2[i]=mi2[i-1]*2%p;
for (int i=0; i<m; ++i){
scanf("%d%d", &a[i], &b[i]); //a b 存边
--a[i]; --b[i]; }
for (int i=0; i<(1<<n); ++i)
for (int j=0; j<m; ++j){
if ((i>>a[j]&1)&&(i>>b[j]&1)) ++c[i]; //c:两边都在s中的点数
if ((i>>a[j]&1)||(i>>b[j]&1)) ++d[i]; //d:恰好一个点在s中的点数
}
for (int i=0; i<2; ++i)
for (int j=0; j<1<<n; ++j){
if ((j>>i&1)==0) continue;
f[i][j]=mi2[c[j]];
for (int k=j; k>0; k=(k-1)&j) //注意是“刚好能到所有点”
f[i][j]=(f[i][j]+p-f[i][j-k]*mi2[c[k]])%p;
}
for (int i=0; i<1<<n; ++i){
for (int j=0; j<1<<n; ++j){
if ((i&j)||c[i]+c[j]!=c[i|j]) continue;
ans=(ans+f[0][i]*f[1][j]%p*mi2[m-d[i|j]])%p; //不与集合相连的边随便选
}
}
printf("%lld\n", (mi2[m]-ans+p)%p);
return 0;
}

Atcoder CF 2017 TR I的更多相关文章

  1. 小trick总结

    一个圆上的整点数量不会很多.(Cf AIM TR 5 F) 二分图完美匹配求字典序最小的方案:先一遍匈牙利求出任意一组完美匹配.再跑一遍逐位确定,要求不能修改编号比它小的匹配.(LG 4100) 如果 ...

  2. 爬虫入门二 beautifulsoup

    title: 爬虫入门二 beautifulsoup date: 2020-03-12 14:43:00 categories: python tags: crawler 使用beautifulsou ...

  3. 2017国家集训队作业Atcoder题目试做

    2017国家集训队作业Atcoder题目试做 虽然远没有达到这个水平,但是据说Atcoder思维难度大,代码难度小,适合我这种不会打字的选手,所以试着做一做 不知道能做几题啊 在完全自己做出来的题前面 ...

  4. [AtCoder Code Festival 2017 QualB D/At3575] 101 to 010 - dp

    [Atcoder Code Festival 2017 QualB/At3575] 101 to 010 有一个01序列,每次可以选出一个101,使其变成010,问最优策略下能操作几次? 考虑像 11 ...

  5. AtCoder Regular Contest 103 E Tr/ee

    Tr/ee 思路:按照下图所示连接 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #inclu ...

  6. 【AtCoder】CODE FESTIVAL 2017 Final

    A - AKIBA 模拟即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair ...

  7. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  8. atcoder/CODE FESTIVAL 2017 qual B/B(dfs染色判断是否为二分图)

    题目链接:http://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c 题意:给出一个含 n ...

  9. AtCoder Regular Contest 075 2017年6月4日 C、D、E题解

    http://arc075.contest.atcoder.jp/assignments 昨晚做的atcoder,今天写个简单题解. F题不会做,800point的,就跪了,要等zk大佬来做.zk能做 ...

随机推荐

  1. 2016.4.6 WinForm显示PDF两种方法

    1.最直接的方法,添加webbrowser控件 webb.Url = new Uri(path);可显示pdf控件. 如果需要在打开时跳转到某页,可用在路径后直接加#page=,例如webb.Url ...

  2. VMware:Configuration file was created by a VMware product with more features than this version

    Few days ago,I opened the Genesys demo VM by VMware Server 1.0.4 and got an error like this: "C ...

  3. AndroidStudio 中使用FFMPEG

    1.下载 FFmpeg 源码 git clone https://git.ffmpeg.org/ffmpeg.git 这一步可能会花比较长的时间 2.编译 FFmpeg for Android 2.1 ...

  4. vs中ffmpeg release版本崩溃问题(转)

    vs2010 win7 下开发视频服务器,用到ffmpeg,debug版本运行正常,切换到release时,出现"0x00905a4d 处未处理的异常: 0xC0000005: 读取位置 0 ...

  5. 浅谈Android四大组建之一Service---Service与Activity的绑定

    从上一篇文章我们学会了如何创建Service,我们通过监听一个按钮,然后再按钮里面通过意图来启动Service.但是我们有没有发现,启动服务以后,Activity和Service之间的联系好像就断开了 ...

  6. 今天出现编码出现了No suitable driver found for jdbc

    出现这样的情况,一般有四种原因: 一:连接URL格式出现了问题(Connection conn=DriverManager.getConnection("jdbc:mysql://local ...

  7. Windows系统上release版本程序bug跟踪解决方案(1)-日志记录

    使用场景: Win32程序在release模式下编译完成,发送给最终用户使用时,我们的程序有时候也会出现崩溃的情况,这个时候如果能快速定位崩溃原因或提供一些程序崩溃时的状态信息,对我们解决问题将会带来 ...

  8. Call requires API level 7 (current min is 1):(问题解决)

    在一个导入的项目里修改加入webView的时候设置缩放属性的设置报错: Call requires API level 7 (current min is 1): android.webkit.Web ...

  9. Mysql GROUP_CONCAT 使用注意事项

    GROUP_CONCAT 函数返回一个字符串结果,该结果由分组中的值连接组合而成,常和 GROUP BY 连用. 如果需要自定义分隔符可以使用 SEPARATOR. 示例: SELECT GROUP_ ...

  10. 【转】nginx+memcached构建页面缓存应用

    如需转载请注明出处: http://www.ttlsa.com/html/2418.html nginx的memcached_module模块可以直接从memcached服务器中读取内容后输出,后续的 ...