题解 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/ ...
随机推荐
- 常用方法 Entitys转换为DataTable
效率比较屁,将近可以用 public static DataTable EntitiesToDataTable<T>(List<T> entitys) { Type t = t ...
- Ubuntu使用小结(主要为后面部署K8s集群做基础铺垫)
包管理 dpkg -L libxml2 #查看libxml2安装了些什么文件 dpkg -s /usr/bin/ls #查看ls是那个包提供的 dpkg -c abc.deb #查看abc. ...
- python自动化测试学习目录
一.python学习目录 <1> ----python驱动 [python驱动]python进行selenium测试时GeckoDriver放在什么地方? python下浏览器静默运行驱动 ...
- UltraISO 下载
链接:https://pan.baidu.com/s/1Wf0TmB8L9falKyGu8NwvBw 提取码:1cu8 参考: https://jingyan.baidu.com/article/cb ...
- [原创]敏捷管理实践Scrum思维导图
[原创]敏捷管理实践Scrum思维导图
- linux运维 技能 2018
1.监控与日志 prometheus.grafana.zabbix ELK(elasticsearch logstash filebeat kibana) 2.容器类 harbor映像管理 docke ...
- 冰多多团队-第二次scrum例会
冰多多团队-第二次Scrum会议 会议基本情况 会议时间:4月8日 19:00 - 19:30 会议地点:新主楼F座2楼沙发休息处 工作情况 团队成员 已完成任务 待完成任务 zpj Service实 ...
- What is the difference between UNION and UNION ALL?
What is the difference between UNION and UNION ALL? UNION removes duplicate records (where all colum ...
- java8在Stream的forEach操作时获取index
import java.util.Objects; import java.util.function.BiConsumer; /** * * @author yangzhilong * @dat ...
- 一个android任务提醒程序
需求: 运行建立多个提醒,每个提醒设置一个时间,到达指定时间后跳出提醒窗体 每个提醒有一个执行按钮,点击后保存执行记录,并且当天不再触发提醒窗体 提醒出现后如果任务还没执行,那么需要在30分钟后再次提 ...