树背包

设f[i][j]表示第i个点,和子节点组成的联通块大小为j,其他都可行的方案

j=0表示可行的总方案

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int mod=1e9+;
int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(''<=ch&&ch<=''){x=x*+ch-'';ch=getchar();}
return x;
} int n,K;
struct node
{
int x,y,next;
}a[];int len,last[];
void ins(int x,int y)
{
len++;
a[len].x=x;a[len].y=y;
a[len].next=last[x];last[x]=len;
}
int f[][],tot[];
void dfs(int x,int fr)
{
f[x][]=;tot[x]=;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(y!=fr)
{
dfs(y,x);
for(int i=tot[x];i>=;i--)
{
for(int j=tot[y];j>=;j--)
f[x][i+j]=(f[x][i+j]+((LL)f[x][i]*(LL)f[y][j])%mod)%mod;
f[x][i]=((LL)f[x][i]*(LL)f[y][])%mod;
}
tot[x]+=tot[y];
}
}
for(int i=K;i<=tot[x];i++)f[x][]=(f[x][]+f[x][i])%mod;
} int main()
{
int x,y;
n=read(),K=read();
len=;memset(last,,sizeof(last));
for(int i=;i<n;i++)
{
x=read(),y=read();
ins(x,y),ins(y,x);
}
memset(f,,sizeof(f));
dfs(,);
printf("%d\n",f[][]);
return ;
}

最新文章

  1. Mac 下 WebStorm 配置go语言开发环境
  2. 在CSDN中添加友情连接
  3. spring:bean的定义
  4. mysql 启动错误1026
  5. 重学STM32----(二)
  6. silverlight 获取路径 config
  7. Linux Shell 脚本
  8. Spark学习笔记-如何运行wordcount(使用jar包)
  9. MySql连接问题
  10. 201521123025《java程序设计》第14周学习总结
  11. 安卓java.lang.IllegalStateException: The specified child already has a parent.解决方案
  12. mysql中replace替换字符串更改方法
  13. mysql处理重复数据
  14. 2.docker的网络模式
  15. k8s 英文文档翻译
  16. rac 关库 启库
  17. 用C#创建XML, XML格式化输出
  18. java设计模式-----21、备忘录模式
  19. model方法取值总结
  20. mac 系统安装VM虚拟机打开时报错,提示不是虚拟磁盘的解决方式。

热门文章

  1. 搭建FileZilla
  2. Flask框架 之重定向、cookie和session
  3. JAVA程序员面试笔试宝典3
  4. Redis系列(十)--集群cluster
  5. ArrayAccess(数组式访问)
  6. 10JDBC、CURD、XML、XPath
  7. HDU-4705 Y(思维+dfs树)
  8. &lt;MyBatis&gt;入门三 sqlMapper文件
  9. java---括号匹配
  10. CodeForcesGym 100753E Change of Scenery