[agc016f]Games on DAG
来源:互联网 发布:网络配线架多少钱 编辑:程序博客网 时间:2024/05/17 07:20
前言
感觉是简单DP。
肯定是状压。
然后你只需要想到按照mex划分即可。
题意
一个有向无环图,求有多少边集的子集组成的图,使得
DP
正难则反,考虑使1和2sg值相等。
设
我们把s划分为A和B,其中B是mex最小的点集,那么A中每个点至少要连向B一条边,B中点可以随意连向A,剩余方案是
我们当然不允许1和2被分离到A和B中,必须同时在A或同时在B。
然后可以预处理
枚举集合以及子集总复杂度是
#include<cstdio>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;typedef long long ll;const int mo=1000000007;bool bz[15+5][15+5];int two[300],id[1<<17];int f[15+5][1<<17],g[15+5][1<<17],dp[1<<17];int i,j,k,l,r,s,t,n,m,ans;int lowbit(int x){ return x&-x;}int main(){ scanf("%d%d",&n,&m); fo(i,1,n) id[1<<(i-1)]=i; two[0]=1; fo(i,1,m) two[i]=(ll)two[i-1]*2%mo; fo(i,1,m){ scanf("%d%d",&j,&k); bz[j][k]=1; } fo(i,1,n) fo(s,1,(1<<n)-1) f[i][s]=f[i][s-lowbit(s)]+bz[i][id[lowbit(s)]]; fo(i,1,n) fo(s,1,(1<<n)-1){ k=id[lowbit(s)]; if (!bz[i][k]) g[i][s]=g[i][s-lowbit(s)]; else g[i][s]=((ll)g[i][s-lowbit(s)]*2%mo+1)%mo; } fo(s,1,(1<<n)-1){ //if (!((s&1)&&(s&2))) continue; dp[s]=1; t=(s-1)&s; while (t){ if (((s^t)&1)&&(t&2)){ t=(t-1)&s; continue; } if (((s^t)&2)&&(t&1)){ t=(t-1)&s; continue; } r=1; fo(i,1,n) if ((t&(1<<(i-1)))) r=(ll)r*g[i][s^t]%mo; l=0; fo(i,1,n) if (((s^t)&(1<<(i-1)))) l+=f[i][t]; r=(ll)r*two[l]%mo; (dp[s]+=(ll)dp[t]*r%mo)%=mo; t=(t-1)&s; } } ans=(two[m]-dp[(1<<n)-1])%mo; (ans+=mo)%=mo; printf("%d\n",ans);}
阅读全文
0 0
- [agc016f]Games on DAG
- Connect Joystick to play games on android
- codeforces 727E. Games on a CD
- Top 10 Games on Linux -sudo update
- DAG
- DAG
- LS 22 Longest path on DAG(最短路+SPFA)
- Always on the run+uva+DAG图上的dp
- UVA - 10913 Walking on a Grid DAG路径最大值
- Games on Symbian OS: A Handbook for Mobile Development
- Programming 3D games on Android with Irrlicht and Bullet
- Programming 3D games on Android with Irrlicht and Bullet
- codeforces 727E. Games on a CD(双Hash
- 论文读书笔记-Multi-Label Classification on Tree- and DAG-Structured Hierarchies
- Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008.eBook-BBL
- (转载)PROGRAMMING 3D GAMES ON ANDROID WITH IRRLICHT AND BULLET
- Can all flash games be readily ported to adobe air for deployment on ios
- Remove Google Play Games libraries on iOS (Unity3D开发之二十一)
- 030 高阶导数求导之推导归纳法、公式法
- 深入理解Java的接口和抽象类
- 时间差 two
- Java线程池ThreadPoolExecutor使用和分析(二)
- Leetcode之Valid Palindrome 问题
- [agc016f]Games on DAG
- 莫队算法
- 排序详解:希尔排序
- 地理路径生成器d3.deo.path()
- 移动架构12_责任链模式
- 死亡
- scala基本语法
- checkboxで表示・非表示を切り替える
- Java JDBC sqlserver连接(增删改)