hdu 3091 Necklace 状态压缩dp *******
2024-09-04 02:09:47
Necklace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others)
Total Submission(s): 522 Accepted Submission(s): 168
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 3
1 2
1 3
2 3
Sample Output
2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std; int n,m;
vector <int> a[];
long long dp[(<<)+][];
void make_ini()
{
int i,j;
int s,r,u;
memset(dp,,sizeof(dp));
dp[][]=;
for(i=;i<(<<n);i++)
{
for(j=;j<n;j++)
{
if(dp[i][j]==)continue;
for(s=;s<a[j].size();s++)
{
u=a[j][s];
if( (i&(<<u))> ) continue;
r=( i | (<<u) );
dp[r][u]+=dp[i][j];
}
}
}
long long Sum=;
for(i=;i<a[].size();i++)
Sum+=dp[(<<n)-][a[][i]];
printf("%I64d\n",Sum);
}
int main()
{
int i,x,y;
while(scanf("%d%d",&n,&m)>)
{
for(i=;i<n;i++)
{
a[i].clear();
}
for(i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
x--;
y--;
a[x].push_back(y);
a[y].push_back(x);
}
make_ini();
}
return ;
}
最新文章
- HTTP 错误 500.23 - Internal Server Error 解决方法
- nullcon HackIM2016 -- Programming Question 3
- Linux内核--异常和中断的区别
- Equipment Box[HDU1110]
- WINDOWS黑客基础(5):利用内存来进行获取计算结果
- Java API —— Calendar类
- 动态规划之HDU水题
- java中事件处理探究
- 2661: [BeiJing wc2012]连连看
- 雪碧图(sprite)
- 玩转Node.js单元测试
- 自学LinkedBlockingQueue源码
- Web API <;五>; 序列化
- Kali学习笔记4:Wireshark详细使用方法
- MySQL数据库Inception工具学习与测试 笔记
- UE4分支的Git Flow
- mongodb中比较级查询条件:($lt $lte $gt $gte)(大于、小于)、查找条件
- Spring 事务 readOnly 到底是怎么回事?
- Mybatis generator代码生成
- MySQL的sql语言分类DML、DQL、DDL、DCL、
热门文章
- php数据库编程---mysql扩展库
- 恢复 MSSQL bak 文件扩展名数据(上)
- 动态sql语句和动态传入参数个数
- weex 自定义Modul
- php 多字节编码转换
- 【Python 解决错误】selenium.common.exception.WebDriverException
- 关于浏览器localhost点击wamp项目跳转出错
- mybatis映射文件模板mapper.xml格式
- C# 直接创建一个DataTable,并为之添加数据(自定义DataTable) 转
- (转)Cobbler自动化部署最佳实践