题解 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/ ...
随机推荐
- vote
package 投票管理; import java.io.*; import java.awt.*; import java.util.*; import java.applet.*; import ...
- Linux yum 包 下载地址
yum包网址: http://www.rpmfind.net/linux/rpm2html/search.php?query=yum
- fork和vfork
转载 http://coolshell.cn/articles/12103.html 在知乎上,有个人问了这样的一个问题——为什么vfork的子进程里用return,整个程序会挂掉,而且exit()不 ...
- LINK : fatal error LNK1181: cannot open input file 'glew32.lib' error: command 'C:\\Program Files (
下载 库文件 参考: https://stackoverflow.com/questions/53355474/kivent-installation-fatal-error-lnk1181-cant ...
- shell中的字符串操作——字符串的切割
default.yaml {default_baseurl: 'http://10.113.10.68:8082'} test.sh a=`cat default.yaml` t=":&qu ...
- Shell 中eval的用法
test.sh:pipe="|"eval ls $pipe wc -l 输出bogon:Desktop macname$ ./test.sh 45 test.sh:eval ech ...
- oracle 根据身份证号计算出生日期
1.情景展示 如何根据身份证号推算出出生日期? 2.解决方案 --根据身份证号计算出生日期 SELECT DECODE(LENGTH(ID_CARD), 18, SUBSTR(ID_CARD, 7 ...
- 【Beta】Scrum Meeting 10 & 发布链接
目录 前言 任务分配 燃尽图 会议照片 签入记录 发布链接(5.17更新) 前言 第10次会议于5月15日22:00在一公寓三楼召开. 交流确认了各自的任务进度,确定了Beta阶段发布的相关事宜.时长 ...
- npm install WARN package.json not exists
npm install WARN package.json not exists: D:\ProData\package.json 一.总结 一句话总结: 出现这样的原因一般是没有切换到指定的目录下, ...
- C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案
C# 序列化与反序列化之Binary与Soap无法对泛型List<T>进行序列化的解决方案 新建Console控制台项目项目,然后添加Team和Person 这2个类,如下: Team和P ...