hdu3091之状态压缩dp
来源:互联网 发布:关键词优化排名 编辑:程序博客网 时间:2024/06/05 01:03
Necklace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others)Total Submission(s): 542 Accepted Submission(s): 173
Problem Description
One day , Partychen gets several beads , he wants to make these beads a necklace . But not every beads can link to each other, every bead should link to some particular bead(s). Now , Partychen wants to know how many kinds of necklace he can make.
Input
It consists of multi-case .
Every case start with two integers N,M ( 1<=N<=18,M<=N*N )
The followed M lines contains two integers a,b ( 1<=a,b<=N ) which means the ath bead and the bth bead are able to be linked.
Every case start with two integers N,M ( 1<=N<=18,M<=N*N )
The followed M lines contains two integers a,b ( 1<=a,b<=N ) which means the ath bead and the bth bead are able to be linked.
Output
An integer , which means the number of kinds that the necklace could be.
Sample Input
3 31 21 32 3
Sample Output
2
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <queue>#include <algorithm>#include <map>#include <cmath>#include <iomanip>#define INF 99999999typedef __int64 LL;using namespace std;const int MAX=(1<<18)+10;int n,m;LL dp[MAX][20];bool edge[20][20];void DP(){int bit=1<<n;memset(dp,0,sizeof dp); dp[1][0]=1;for(int i=1;i<bit;++i){for(int j=0;j<n;++j){if(dp[i][j] == 0)continue;for(int k=1;k<n;++k){if(i&(1<<k))continue;if(!edge[j][k])continue;dp[i|(1<<k)][k]+=dp[i][j];}}}LL sum=0;for(int i=0;i<n;++i)if(edge[0][i])sum+=dp[bit-1][i];printf("%I64d\n",sum);}int main(){int u,v;while(~scanf("%d%d",&n,&m)){memset(edge,false,sizeof edge);for(int i=0;i<m;++i){scanf("%d%d",&u,&v);--u,--v;edge[u][v]=edge[v][u]=true;}DP();}return 0;}
0 0
- hdu3091之状态压缩dp
- hdu3091 状态压缩~方案数
- poj1185之状态压缩dp
- hdu1565之状态压缩dp
- hdu4539之状态压缩dp
- hdu3254之状态压缩dp
- hdu1074之状态压缩dp
- hdu4628之状态压缩dp
- hdu3311之状态压缩dp
- hdu4049之状态压缩dp
- hdu3681之状态压缩dp
- hdu4284之状态压缩dp
- hdu2817之状态压缩dp
- ZOJ2563 之状态压缩dp
- hdu3471之状态压缩dp
- hdu 3920之状态压缩dp
- 状态压缩DP 之 poj 2686
- hdu4336之状态压缩慨率DP
- VC++,掀起你的盖头来 ——谈VC++对象模型
- POJ 2965The Pilots Brothers' refrigerator (bfs)
- 分布式数据库【2、两阶段提交协议2PC】【部分转载】
- 老师,这绝对是我一行一行敲出来的
- gcc与g++的区别
- hdu3091之状态压缩dp
- 一则C++程序设计课堂练习的记录
- SpringMvc(三)配置Mybatis
- 如何求FIRST集和FOLLOW集
- Socket编程原理
- eclipse
- UVA 11400 Lighting System Design(贪心+DP)
- ArcGIS 10.1 for Server 在windows下的安装
- 课题实验(一)