题意:

  给一个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】的更多相关文章

  1. CF53E Dead Ends

    CF53E Dead Ends 洛谷评测传送门 题目描述 Life in Bertown has become hard. The city has too many roads and the go ...

  2. [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 ...

  3. Codeforces Gym 100531I Instruction 构造

    Problem I. Instruction 题目连接: http://codeforces.com/gym/100531/attachments Description Ingrid is a he ...

  4. LeetCode 752. Open the Lock

    原题链接在这里:https://leetcode.com/problems/open-the-lock/ 题目: You have a lock in front of you with 4 circ ...

  5. 张洋:浅析PageRank算法

    本文引自http://blog.jobbole.com/23286/ 很早就对Google的PageRank算法很感兴趣,但一直没有深究,只有个轮廓性的概念.前几天趁团队outing的机会,在动车上看 ...

  6. [转载]Context and Interception : The .NET Context

    转载自:Context and Interception : The .NET Context Every new app domain starts with a single context, c ...

  7. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  8. [IR] Information Extraction

    阶段性总结 Boolean retrieval 单词搜索 [Qword1 and Qword2]               O(x+y) [Qword1 and Qword2]- 改进: Gallo ...

  9. [IR] Link Analysis

    网络信息的特点在于: Query: "IBM" --> "Computer" --> documentIDs. In degree i 正比于 1/ ...

随机推荐

  1. (1)IdentityServer4 V3.0.2-安装模板

    控制台运行命令: dotnet new -i IdentityServer4.Templates

  2. Numpy | 15 数学函数

    NumPy 包含大量的各种数学运算的函数,包括三角函数,算术运算的函数,复数处理函数等. 三角函数 NumPy 提供了标准的三角函数:sin().cos().tan(). import numpy a ...

  3. centos7 安装 bugfree3

    . 安装apache yum install httpd . 安装mysql wget -i -c http://dev.mysql.com/get/mysql57-community-release ...

  4. 利用python爬虫爬取图片并且制作马赛克拼图

    想在妹子生日送妹子一张用零食(或者食物类好看的图片)拼成的马赛克拼图,因此探索了一番= =. 首先需要一个软件来制作马赛克拼图,这里使用Foto-Mosaik-Edda(网上也有在线制作的网站,但是我 ...

  5. jenkins使用--安装文档

    添加Jenkins的源(repository): #sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/je ...

  6. pyqt(day2)

    一.安装python 二.安装pyqt5 pip install pyqt5 三.安装pycharm 四.第一个pyqt程序 import sys from PyQt5.QtWidgets impor ...

  7. Gevent简明教程

    Gevent简明教程  发表于 2015-11-28 |  分类于 技术| |  阅读次数 5159 前述 进程 线程 协程 异步 并发编程(不是并行)目前有四种方式:多进程.多线程.协程和异步. 多 ...

  8. HIVE-计算累计和

    eg:统计1-12月的累积销量,即1月为1月份的值,2月为1.2月份值的和,3月为123月份的和,12月为1-12月份值的和 SELECT   month,SUM(amount) month_amou ...

  9. 解析生效测试方法 执行命令 ping 域名 得不到 IP 主要有如下几个原因:

    https://help.aliyun.com/knowledge_detail/39834.html dig https://cloud.tencent.com/document/product/3 ...

  10. 取response里 Json格式的字段值

    1.