题解 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/ ...
随机推荐
- MongoDB shell 3 集合方法
方法名 描述 db.collection.aggregate() 聚合,主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果 db.collection.bulkWrite() 批量写入 ...
- Linux下Python3源码安装
1.下载 wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz 2.解压 tar -xzvf Python-3.7.4.tgz 3 ...
- bzoj4066: 简单题 K-Dtree
bzoj4066: 简单题 链接 bzoj 思路 强制在线.k-dtree. 卡常啊.空间开1e6就T了. 代码 #include <bits/stdc++.h> #define my_m ...
- A@G!C005
AGC005 A STring 不会,有没有老鸽蕉蕉我/kk/kel/dk https://agc005.contest.atcoder.jp/submissions/7926986 B Minimu ...
- python爬虫出现ProxyError: HTTPSConnectionPool错误
在今天刚刚打开pycharm运行爬虫时,发现所有的爬虫都不能运行,会出现如下的错误: 错误出现的主要原因是;代理错误(其实自己根本没有设置代理) 解决方法: 在网上查阅了许多类似的错误解决方法,试过后 ...
- TDD(测试驱动开发)
什么是 TDDTDD 有广义和狭义之分,常说的是狭义的 TDD,也就是 UTDD(Unit Test Driven Development).广义的 TDD 是 ATDD(Acceptance Tes ...
- player: 初始化分析
//1. //cocos 程序开始运行时执行的函数 bool AppDelegate::applicationDidFinishLaunching() { // initialize director ...
- 组合模式( Composite Pattern)
参考文档:http://blog.csdn.net/ai92/article/details/298336 定义: 组合多个对象形成树形结构以表示“整体-部分”的结构层次. 设计动机: 这幅图片我们都 ...
- [技术博客] 用户验证码验证机制---redis缓存数据库的使用
目录 问题引入 初识redis 实际应用 作者:马振亚 问题引入 在这次的开发过程中,我们的需求中有一个是普通用户可以通过特定的机制申请成为社长.因为只有部分人才能验证成功,所以这个最开始想了两种思路 ...
- uniapp - 文字收缩展示插件
插件地址:https://ext.dcloud.net.cn/plugin?id=657