[ZJOI 2016] 小星星
4455: [Zjoi2016]小星星
Time Limit: 10 Sec Memory Limit: 512 MB
Submit: 653 Solved: 400
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2
1 3
1 4
4 1
4 2
4 3
Sample Output
#include<bits/stdc++.h>
#define ll unsigned long long
#define maxn 140005
#define pb push_back
using namespace std;
vector<int> g[20];
int num,point[20];
int a[20][20],n,m,ci[30],S;
ll f[20][20],ans[maxn];
// ans[S]表示选点集合只能是S子集的方案数 void dp(int x,int fa){
for(int i=1;i<=num;i++) f[x][i]=1;
int to;
for(int i=g[x].size()-1;i>=0;i--){
to=g[x][i];
if(to==fa) continue;
dp(to,x); for(int j=1;j<=num;j++){
ll now=0;
for(int k=1;k<=num;k++) if(a[point[j]][point[k]]) now+=f[to][k];
f[x][j]*=now;
}
}
} int main(){
ci[0]=1;
for(int i=1;i<=20;i++) ci[i]=ci[i-1]<<1; int uu,vv;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&uu,&vv);
a[uu][vv]=a[vv][uu]=1;
}
for(int i=1;i<n;i++){
scanf("%d%d",&uu,&vv);
g[uu].pb(vv),g[vv].pb(uu);
} for(S=1;S<ci[n];S++){
num=0,memset(f,0,sizeof(f));
for(int i=1;i<=n;i++) if(ci[i-1]&S) point[++num]=i;
dp(1,1);
for(int i=1;i<=num;i++) ans[S]+=f[1][i];
} for(int i=1;i<ci[n];i++)
for(int j=(i-1)&i;j;j=(j-1)&i) ans[i]-=ans[j]; printf("%llu\n",ans[ci[n]-1]);
return 0;
}
[ZJOI 2016] 小星星的更多相关文章
- [BZOJ 4455] [ZJOI 2016] 小星星 (树形dp+容斥原理+状态压缩)
[BZOJ 4455] [ZJOI 2016] 小星星 (树形dp+容斥原理+状态压缩) 题面 给出一棵树和一个图,点数均为n,问有多少种方法把树的节点标号,使得对于树上的任意两个节点u,v,若树上u ...
- [BZOJ 4573][ZJOI 2016]大森林
[LOJ 2092][BZOJ 4573][UOJ 195][ZJOI 2016]大森林 题意 给定一个树序列, 初始时所有树都只有一个点, 要求支持三种操作: 区间种树(在某个特定点上长出一个子结点 ...
- 【BZOJ 4455】【UOJ #185】【ZJOI 2016】小星星
http://www.lydsy.com/JudgeOnline/problem.php?id=4455 http://uoj.ac/problem/185 有一个$O(n^n)$的暴力,放宽限制可以 ...
- 【BZOJ 4456】【UOJ #184】【ZJOI 2016】旅行者
http://www.lydsy.com/JudgeOnline/problem.php?id=4456 http://uoj.ac/problem/184 参考(抄)的晨爷的题解(代码) 对矩形进行 ...
- 【ZJOI 2016】旅行者
题意 http://uoj.ac/problem/184 题解 大概是神题. 网格图上跑最短路有一个经典的优化方式:分治分组跑最短路. 对于这道题,设矩形长为 \(n\),宽为 \(m\),则对 \( ...
- Solution -「ZJOI 2016」「洛谷 P3352」线段树
\(\mathcal{Descrtiption}\) 给定 \(\{a_n\}\),现进行 \(m\) 次操作,每次操作随机一个区间 \([l,r]\),令其中元素全部变为区间最大值.对于每个 \ ...
- zjoi 小星星
题解: dp很容易想 f[i][j][s]表示匹配到了i点 对应点为j点,状态为s 那么这样的时间复杂度为(3^n*n^2) 然后会发现这其实可以转化为可以重复利用元素的子集卷积 http://www ...
- @loj - 2091@ 「ZJOI2016」小星星
目录 @description@ @solution@ @accepted code@ @details@ @description@ 小 Y 是一个心灵手巧的女孩子,她喜欢手工制作一些小饰品.她有 ...
- Be Better:遇见更好的自己-2016年记
其实并不能找到好的词语来形容过去的一年,感觉就如此平淡的过了!没有了毕业的稚气,看事情淡了,少了一丝浮躁,多了一分认真.2016也许就是那句话-多读书,多看报,少吃零食多睡觉,而我更愿意说--Be B ...
随机推荐
- Leetcode 81. 搜索旋转排序数组 II
题目链接 https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/description/ 题目描述 假设按照升序排序的数 ...
- Java装饰者模式(Decorator)
一.定义 装饰模式的设计理念主要是以对客户端透明的方式动态扩展对象的功能,是继承关系的一个替代(继承会产生大量的子类,而且代码有冗余).装饰模式可以在不创造更多子类的情况下,将对象的功能加以扩展.装饰 ...
- luogu3193 [HNOI2008]GT考试
there #include <iostream> #include <cstdio> using namespace std; int n, m, mod, nxt[25], ...
- Sogou日志分析(hive)
1. 数据准备 1.1 数据预先放在mac本地桌面的“VB共享文件夹”中,从VisualBox虚拟机中/mnt/VBShare共享目录中转移到resources目标目录. [cloudera@quic ...
- Django底层原理简介与安装
Django环境目录搭建一栏: 利用wsgiref模块封装好的socket搭建服务端: #利用wsgiref模块封装好的socket演示操作(例如accept\recv) #也可以实现socket服务 ...
- Python循环语句 if while for
流程控制: if 条件1: 缩进的代码块 (注意缩进4个空格) elif 条件2: 缩进的代码块 elif 条件3: 缩进的代码块 ...... else: 缩进的代码块 注意1:(相同的代码块儿,同 ...
- install and config redis on ubuntu14.04
1.installation: (1)download redis from http://redis.io/download (2)installation: $ tar -xvf redis-3. ...
- 组合数学之Polya计数 TOJ1116 Let it Bead
1116: Let it Bead Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByteTotal Submit: 7 ...
- 图标字体iconfont的使用
什么是iconfont? iconfont就是字面上的意思,叫做"字体图标",将一套图标集以字体文件的形式封装,并通过 CSS 的 @font-face 作为 Web Font 调 ...
- ubuntu14.04修改mysql默认编码
修改文件为/etc/mysql/my.cnf [client] default-character-set = utf8 (ps:client的设置没变) [mysqld] lower_case_ta ...