题解 CF53E 【Dead Ends】
题意:
给一个n(n<=10)个节点的无向图,图里面有m条边,以这m条边构建生成树,求所有生成树中只含有k个度数为1的点的方案数。
题解:
看见这个数量级就一定会想到状态压缩dp...
那让我们设计一下状态:
dp[i][j] 表示生成树的状态为i时,所含的度数为1的点的状态j的方案数。
那么就可以进行状态转移了,每次有两种更新方式:
1:加入一条边(也就是一个新点)到原来度数为1的点,相当于替换了。
2:把边加到一个度数不为1的节点上。
时间复杂度:
O(能过)
废话少说上代码:
#include<bits/stdc++.h>
using namespace std;
const int maxs=(<<)+;
vector<int> mapp[];
int dp[maxs][maxs],cnt1[maxs];
int n,m,k;
void init(){
for(int i=;i<=maxs;i++)
for(int k=;k<+;k++)
if(i&(<<k))
cnt1[i]++;
}
int main(){
init();
scanf("%d%d%d",&n,&m,&k);
int x,y;
for(int i=;i<=m;i++){
scanf("%d%d",&x,&y); x--;y--;
mapp[x].push_back(y);mapp[y].push_back(x);
}
for(int i=;i<=(<<n)-;i<<=) dp[i][i]=;
for(int i=;i<=(<<n)-;i++)
for(int j=i;j;--j&=i)
if(dp[i][j])
for(int e=;e<n;e++)
if(i&(<<e))
for(int r=;r<mapp[e].size();r++){
int to=mapp[e][r],now;
if(~i&(<<to)){
if(cnt1[i]==) now=i|(<<to);
else now=j&~(<<e)|(<<to);
if(!(now>>to+)) dp[i|(<<to)][now]+=dp[i][j];
}
}
long long ans=;
for(int i=;i<=(<<n)-;i++)
if(cnt1[i]==k)
ans+=dp[(<<n)-][i];
printf("%lld",ans);
return ;
}
题解 CF53E 【Dead Ends】的更多相关文章
- CF53E Dead Ends
CF53E Dead Ends 洛谷评测传送门 题目描述 Life in Bertown has become hard. The city has too many roads and the go ...
- [TypeScript] Use the never type to avoid code with dead ends using TypeScript
Example 1: A never stop while loop return a never type. function run(): never { while(true){ let foo ...
- Codeforces Gym 100531I Instruction 构造
Problem I. Instruction 题目连接: http://codeforces.com/gym/100531/attachments Description Ingrid is a he ...
- LeetCode 752. Open the Lock
原题链接在这里:https://leetcode.com/problems/open-the-lock/ 题目: You have a lock in front of you with 4 circ ...
- 张洋:浅析PageRank算法
本文引自http://blog.jobbole.com/23286/ 很早就对Google的PageRank算法很感兴趣,但一直没有深究,只有个轮廓性的概念.前几天趁团队outing的机会,在动车上看 ...
- [转载]Context and Interception : The .NET Context
转载自:Context and Interception : The .NET Context Every new app domain starts with a single context, c ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- [IR] Information Extraction
阶段性总结 Boolean retrieval 单词搜索 [Qword1 and Qword2] O(x+y) [Qword1 and Qword2]- 改进: Gallo ...
- [IR] Link Analysis
网络信息的特点在于: Query: "IBM" --> "Computer" --> documentIDs. In degree i 正比于 1/ ...
随机推荐
- sqlg rdbms 上实现的Apache TinkerPop
sqlg 可以让关系型数据库支持Apache TinkerPop,当前支持的数据库有postgresql,hsqldb,h2,mariadb,mysql,mssqlserver 以下是一个简单的使用 ...
- 使用haproxy 2.0 prometheus metrics 监控系统状态
haproxy 2.0 已经发布一段时间了,提供内部直接暴露的prometheus metrics 很方便 ,可以快速的监控系统的状态 以下是一个简单的demo 环境准备 docker-compose ...
- 解决mysql无法显示中文/MySQL中文乱码问号等问题
一般都是编码格式问题 显示编码格式: show variables like'character_set_%'; 将其中Value不是utf8的改为utf8: set character_set_cl ...
- http 缓存机制简介
我们应该从两个角度来看http的缓存:缓存控制 和 缓存校验.缓存控制:控制缓存的开关,用于标识请求或访问中是否开启了缓存,使用了什么样的存方式.缓存校验:如何校验缓存,缓存的有效期,如何确定缓存是最 ...
- Note_3.31
2019/4/1 奇奇怪怪的笔记 整理了一些之前没有写过的东西,把它们拼在一起,并没有什么逻辑可言qwq FWT快速沃尔什变换 \[ FWT(A)=merge(FWT(A0),FWT(A0+A1)) ...
- layui之table.render使用(含后台详细代码实现)
效果图如下: 前端实现代码如图(完整代码): <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...
- 【Gamma】Scrum Meeting 3
目录 写在前面 进度情况 任务进度表 Gamma阶段燃尽图 照片 写在前面 例会时间:5.27 22:30-23:30 例会地点:微信群语音通话 代码进度记录github在这里 临近期末,团队成员课程 ...
- 从太空到地球某个位置的轨迹录像制作 | Earth Zoom in/out Tutorial (Record Video)
视频教程:Google Earth - Earth Zoom in/out Tutorial (Record Video) 下载google earth 在search里输入你想要去的地名 zoom ...
- Oracle 导出表结构
Oracle导出表结构 select A.Table_Name 表名 , -- A.column_name 字段名 A.column_name 字段名, A.data_type 数据类型, A.dat ...
- virtualenv, conda, pip分别是什么
自己一直使用virtualenv,但是发现很多工具或框架都是以来conda,于是就网上搜了下二者的区别,感觉这篇文章讲的比较清楚:https://blog.csdn.net/zhouchen1998/ ...