O
来源:互联网 发布:火箭队球迷 知乎 编辑:程序博客网 时间:2024/06/07 19:12
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.
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.
3 31 21 32 3
2
题意:
给你几个贝壳,每个贝壳能和特定的贝壳相连,问最多可组成多少种项链?
思路:
状态dp,寻找每个位置
代码;'
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>typedef __int64 ll;using namespace std;int n,m;bool mp[25][25];ll dp[1<<18][25];void solve(){ 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(!mp[j][k])continue; dp[i|(1<<k)][k]+=dp[i][j]; } } } ll ans=0; for(int i=0;i<n;i++) if(mp[0][i])ans+=dp[bit-1][i]; cout<<ans<<endl;}int main(){ ios::sync_with_stdio(false); int x,y; int i; while(cin>>n>>m){ memset(mp,0,sizeof(mp)); for(i=0;i<m;i++){ cin>>x>>y; --x,--y; mp[x][y]=mp[y][x]=1; } solve(); } return 0;}
阅读全文
0 0
- [O
- o,
- o
- o~~
- /(^o^)/~
- o
- O
- O
- O
- O
- O
- O
- O
- O
- O
- O
- O
- O
- android 新增分区以及挂载方法
- 基于FFmpeg+VAAPI的硬件加速渲染技术
- Intel IDEA 系列工具,根据个人习惯做的配置优化
- 深入理解express框架
- python pandas 统计性质
- O
- Python,函数(1)
- Win10以管理员身份打开命令提示符CMD的3种方法
- 简单设计并开发一个移动通信程序
- SqlServer列传行+动态sql
- 超初级的用Python收集杂乱字符串中的特定字符,统计出每个特定字符的出现次数并取出最小值
- 171206-类与对象【连续第四十二天】
- opencv之画图(Drawing Functions in OpenCV )
- thinkphp3.2 中用S方法实现 用户定时操作