dalao教导我们,看到计数想容斥……
卡常策略:枚举顺序、除去无效状态、(树结构)

#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;
const int N=;
LL f[N][N];
int n,m,d[N][N],full;
bool yeah[N];
int st[N],cnt;
struct V{
int to,next;
}c[N<<];
int head[N],t;
inline void add(int x,int y){
c[++t].to=y,c[t].next=head[x],head[x]=t;
}
inline void dfs(int x,int fa){
register int i,j,k;LL sum=;
for(i=head[x];i;i=c[i].next)
if(c[i].to!=fa)
dfs(c[i].to,x);
for(i=;i<=n;++i){
if(!yeah[i]){
f[x][i]=;
continue;
}
f[x][i]=;
for(j=head[x];j;j=c[j].next)
if(c[j].to!=fa){
sum=;
for(k=;k<=cnt;++k)
if(d[i][st[k]])
sum+=f[c[j].to][st[k]];
f[x][i]*=sum;
}
}
}
int main(){
scanf("%d%d",&n,&m);
full=(<<n)-;
int i,j,x,y;
for(i=;i<=m;++i){
scanf("%d%d",&x,&y);
d[x][y]=d[y][x]=;
}
for(i=;i<n;++i){
scanf("%d%d",&x,&y);
add(x,y),add(y,x);
}
LL ans=,sum;
for(i=;i<=full;++i){
cnt=,sum=;
for(j=;j<n;++j)
if(i&(<<j))yeah[j+]=true,st[++cnt]=j+;
else yeah[j+]=false;
dfs(,);
for(j=;j<=n;++j)
sum+=f[][j];
ans+=(((n-cnt)&)?-:)*sum;
}
printf("%lld\n",ans);
return ;
}

【BZOJ 4455】 [Zjoi2016]小星星 容斥计数的更多相关文章

  1. BZOJ 4455: [Zjoi2016]小星星(容斥+树形dp)

    传送门 解题思路 首先题目中有两个限制,第一个是两个集合直接必须一一映射,第二个是重新标号后,\(B\)中两点有边\(A\)中也必须有.发现限制\(2\)比较容易满足,考虑化简限制\(1\).令\(f ...

  2. 4455[Zjoi2016]小星星 容斥+dp

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 527  Solved: 317[Submit][Status] ...

  3. bzoj 4455 [Zjoi2016]小星星 树形dp&容斥

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 643  Solved: 391[Submit][Status] ...

  4. BZOJ 4455: [Zjoi2016]小星星 [容斥原理 树形DP]

    4455: [Zjoi2016]小星星 题意:一个图删掉一些边形成一棵树,告诉你图和树的样子,求让图上的点和树上的点对应起来有多少方案 看了很多题解又想了一段时间,感觉题解都没有很深入,现在大致有了自 ...

  5. BZOJ 4455: [Zjoi2016]小星星

    Sol 容斥原理+树形DP. 这道题用的容斥思想非常妙啊!主要的思路就是让所有点与S集合中的点对应,可以重复对应,并且可以不用对应完全(意思是是S的子集也可以).这样他有未对应完全的,那就减去,从全都 ...

  6. UOJ185 ZJOI2016 小星星 容斥、树形DP

    传送门 先考虑一个暴力的DP:设\(f_{i,j,S}\)表示点\(i\)映射到了图中的点\(j\),且点\(i\)所在子树的所有点映射到了图中的集合\(S\)时的映射方案数,转移暴力地枚举子集即可, ...

  7. 【BZOJ 4455】 4455: [Zjoi2016]小星星 (容斥原理+树形DP)

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 426  Solved: 255 Description 小Y是 ...

  8. 【BZOJ-4455】小星星 容斥 + 树形DP

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 137[Submit][Status] ...

  9. 「LOJ2091」「ZJOI2016」小星星 容斥+DP

    题目描述 小 Y 是一个心灵手巧的女孩子,她喜欢手工制作一些小饰品.她有\(n\)颗小星星,用 \(m\)条彩色的细线串了起来,每条细线连着两颗小星星.有一天她发现,她的饰品被破坏了,很多细线都被拆掉 ...

随机推荐

  1. 【SpringCloud】第三篇: 服务消费者(Feign)

    前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...

  2. Unity Lighting - Choosing a Lighting Technique 选择照明技术(一)

      Choosing a Lighting Technique 选择照明技术 https://unity3d.com/cn/learn/tutorials/topics/graphics/choosi ...

  3. CDH/Hadoop 5.15 installation steps

    I will talk the main steps to install CDH 5.15 on Linux(CENT OS 6.10).  The installation method is M ...

  4. Executor Framework

    Why? look at the following 2 pieces of code for implementing a simple web server based on socket, ca ...

  5. opencv-学习笔记(1)常用函数和方法。

    opencv-学习笔记(1)常用函数和方法. cv2.imread(filename,falg) filename是文件名字 flag是读入的方式 cv2.MREAD_UNCHANGED :不进行转化 ...

  6. C语言struct中的长度可变数组(Flexible array member)

    C_struct中的长度可变数组(Flexible array member) Flexible array member is a feature introduced in the C99 sta ...

  7. 一个改变this指向bind的函数,vue源代码

    function bind(fn, ctx) { return function (a) { var l = arguments.length; return l ? l > 1 ? fn.ap ...

  8. 条款03 尽可能使用const

    一.概述 使用const约束对象:可以获得编译器的帮助(指出相关出错的地方) const与成员函数:const重载.转型.避免代码重复 二.细节 1. 为什么有些函数要返回const对象(看上去没必要 ...

  9. return阻止js继续向下执行

    终止JS运行有如下几种可能: 终止函数的运行的方式有两种 在函数中使用return,则当遇到return时,函数终止执行,控制权继续向下运行 在函数中使用try-catch异常处理,需要结束时,使用t ...

  10. 一个demo让你彻底理解Android中触摸事件的分发

    注:本文涉及的demo的地址:https://github.com/absfree/TouchDispatch 1. 触摸动作及事件序列 (1)触摸事件的动作 触摸动作一共有三种:ACTION_DOW ...