【NOIP2017模拟赛】二分图+状态压缩DP Graph(好题)
来源:互联网 发布:2017fc2破解版域名设置 编辑:程序博客网 时间:2024/06/05 06:52
题解
这道题其实是一个
此时我们考虑状态压缩DP,
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define N 25#define mod 998244353#define P 1048580int n,m,lg2[P],bit[P];bool A[N][N];int f[N][P];int getint(){ int p=0; char c=getchar(); while(c<'0'||c>'9')c=getchar(); while(c>='0'&&c<='9')p=p*10+c-'0',c=getchar(); return p;}int main(){ n=getint();m=getint(); lg2[1]=1;bit[1]=1; for(int i=2;i<=(1<<20);i++) { lg2[i]=lg2[i>>1]+1; for(int j=0;j<=20;j++) if(i&(1<<j)) bit[i]++; } for(int i=1;i<=m;i++) { int a=getint(),b=getint(); A[a][b]=1; } f[0][0]=1; for(int i=1;i<=n;i++) { for(int j=1;j<(1<<n);j++) { if(bit[j]!=i) continue; for(int k=j;k;k-=k&-k) { int v=lg2[k&-k]; if(A[i][v]) f[i][j]=(f[i][j]+f[i-1][j-(k&-k)])%mod; } } } printf("%d\n",f[n][(1<<n)-1]);}
阅读全文
0 0
- 【NOIP2017模拟赛】二分图+状态压缩DP Graph(好题)
- NOIP2017模拟赛 好线路(dp)
- 【NOIP2017模拟赛】构造 A+B Problem(好题)
- (POJ 3254)Corn Fields <状态压缩DP 好题>
- NOIP2017模拟赛 不等数列(dp)
- NOIP2017赛前模拟 Graph (2017.10.24)
- E. Vladik and cards Codeforces Round #384 (Div. 2) 好题 二分+(贪心+状态压缩DP)判断
- HDU3681Prison Break(BFS+TSP+二分+dp状态压缩)
- light oj 1147 背包dp+状态压缩 好题
- hdu 3001 Travelling (状态压缩dp-----模拟三进制)
- NOIP2017模拟赛 龙珠(dp+单调队列优化)
- 2014上海网络赛1004||hdu5045 二分图的最佳匹配 或 状态压缩dp
- BFS+状态压缩DP+二分枚举+TSP
- hdu 3681 二分+状态压缩dp+bfs
- hdu3681(二分+状态压缩dp+bfs)
- 【NOIP2017模拟赛】思维+转化+图论 徒然Children(好题)
- zoj 1100&& poj2411 Mondriaan's Dream (dfs&&枚举&&状态压缩dp)好题
- hdu5313 Bipartite Graph(二分图染色+dp+位运算)
- 习题6-2 S-Trees UVA
- Pojo和JavaBean的区别
- sdk开发中如何去捕获系统的didReceiveLocalNotification以及didReceiveRemoteNotification通知
- 听说有些老铁,要感谢下大师兄?扫一扫,领红包啦。顺便打赏我个0.01¥怎么样?
- Android学习之ListView
- 【NOIP2017模拟赛】二分图+状态压缩DP Graph(好题)
- 为什么这题交上去显示wrong answer?
- 伪随机数rand()与srand()学习心得
- MySQL练习时所遇问题
- IDA动态调试技术及Dump内存
- Java 技术之垃圾回收机制
- Java主流几大框架的对比(EasyUI,Bootstrap,Struts2,SpingMvc,Ejb,Spring,Hibernate,Mybatis)
- Error:Unable to resolve dependency for ':app@stage/compileClasspath': Could not resolve project :mvp
- 哲学家就餐问题的思考(java实现)