题目描述

Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k k k -tree.

A k k k -tree is an infinite rooted tree where:

  • each vertex has exactly k k k children;
  • each edge has some weight;
  • if we look at the edges that goes from some vertex to its children (exactly k k k edges), then their weights will equal 1,2,3,...,k 1,2,3,...,k 1,2,3,...,k .

The picture below shows a part of a 3-tree.

As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n n n (the sum of all weights of the edges in the path) are there, starting from the root of a k k k -tree and also containing at least one edge of weight at least d d d ?".Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 1000000007 1000000007 ( 109+7 10^{9}+7 109+7 ).

输入输出格式

输入格式:

A single line contains three space-separated integers: n n n , k k k and d d d ( 1<=n,k<=100; 1<=n,k<=100; 1<=n,k<=100; 1<=d<=k 1<=d<=k 1<=d<=k ).

输出格式:

Print a single integer — the answer to the problem modulo 1000000007 1000000007 1000000007 ( 109+7 10^{9}+7 109+7 ).

输入输出样例

输入样例#1: 复制

3 3 2
输出样例#1: 复制

3
输入样例#2: 复制

3 3 3
输出样例#2: 复制

1
输入样例#3: 复制

4 3 2
输出样例#3: 复制

6
输入样例#4: 复制

4 5 2
输出样例#4: 复制

7


简单的DP。
设f[i][j][0/1]为目前在深度为i,和为j,是否出现多大于等于d的边的方案数。
然后随便转移。
因为转移比较特色可以省掉第一维。
貌似网上还有别的方法。
f[i][j]表示和为i,出现的最大边权是j的方案数。
f[i+k][max(j,k)] += f[i][j]。


#include <bits/stdc++.h>
using namespace std;
#define reg register
#define mod 1000000007
int n, K, d;
int f[][][];
int ans; int main()
{
scanf("%d%d%d", &n, &K, &d);
f[][][] = ;
for (reg int i = ; i <= n ; i ++) //dep
{
for (reg int j = ; j <= n ; j ++) //tot val
{
for (reg int k = ; k <= K ; k ++) //the edge run
{
if (j - k < ) break;
if (k >= d) f[i][j][] = (f[i][j][] + f[i-][j-k][]) % mod;
else f[i][j][] = (f[i][j][] + f[i-][j-k][]) % mod;
f[i][j][] = (f[i][j][] + f[i-][j-k][]) % mod;
}
}
}
for (reg int i = ; i <= n ; i ++) ans = (ans + f[i][n][]) % mod;
cout << ans << endl;
return ;
}

[CF431C]k-Tree的更多相关文章

  1. E - Count on a tree 树上第K小

    主席树的入门题目,这道题的题意其实就是说,给你一棵树,询问在两个节点之间的路径上的区间第K小 我们如何把树上问题转换为区间问题呢? 其实DFS就可以,我们按照DFS的顺序,对线段树进行建树,那么这个树 ...

  2. AOJ DSL_2_C Range Search (kD Tree)

    Range Search (kD Tree) The range search problem consists of a set of attributed records S to determi ...

  3. HDU3333 Turing Tree(线段树)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=3333 Description After inventing Turing Tree, 3x ...

  4. Codeforces 343D Water Tree(DFS序 + 线段树)

    题目大概说给一棵树,进行以下3个操作:把某结点为根的子树中各个结点值设为1.把某结点以及其各个祖先值设为0.询问某结点的值. 对于第一个操作就是经典的DFS序+线段树了.而对于第二个操作,考虑再维护一 ...

  5. Codeforces 620E New Year Tree(DFS序 + 线段树)

    题目大概说给一棵树,树上结点都有颜色(1到60),进行下面两个操作:把某结点为根的子树染成某一颜色.询问某结点为根的子树有多少种颜色. 子树,显然DFS序,把子树结点映射到连续的区间.而注意到颜色60 ...

  6. POJ3321 Apple Tree(DFS序)

    题目,是对一颗树,单点修改.子树查询.典型的dfs序入门题. DFS序可以将一颗树与子树们表示为一个连续的区间,然后用线段树来维护:感觉算是树链剖分的一种吧,和轻重链剖分不同的是这是对子树进行剖分的. ...

  7. poj3237 Tree

    Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...

  8. Size Balanced Tree(SBT) 模板

    首先是从二叉搜索树开始,一棵二叉搜索树的定义是: 1.这是一棵二叉树: 2.令x为二叉树中某个结点上表示的值,那么其左子树上所有结点的值都要不大于x,其右子树上所有结点的值都要不小于x. 由二叉搜索树 ...

  9. [模板] K-D Tree

    K-D Tree K-D Tree可以看作二叉搜索树的高维推广, 它的第 \(k\) 层以所有点的第 \(k\) 维作为关键字对点做出划分. 为了保证划分均匀, 可以以第 \(k\) 维排名在中间的节 ...

  10. HDU 2665.Kth number 区间第K小

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. C#中using的使用-以FileStream写入文件为例

    场景 CS中FileStream的对比以及使用方法: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100396022 关注公众号 ...

  2. sql server之SQL SELECT INTO 语句

    SELECT INTO 语句可用于创建表的备份复件. SELECT INTO 语句 SELECT INTO 语句从一个表中选取数据,然后把数据插入另一个表中. SELECT INTO 语句常用于创建表 ...

  3. (五)Linux内存管理zone_sizes_init

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...

  4. Tcloud 云测平台-使用介绍

    Tcloud使用介绍 前端github地址:https://github.com/bigbaser/Tcloud后端github地址:https://github.com/bigbaser/Tclou ...

  5. 网站启动,报编译错误:类型“ASP.global_asax”同时存在两个文件夹的问题

    CS0433: The type 'ASP.global_asax' exists in both 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\T ...

  6. 【linux】记录一个yum update和upgrade的区别

    yum update 更新软件包和系统软件.系统内核 yum upgrade只更新软件包,不更新系统软件和系统内核 查看版本号 [root@localhost ~]# uname -r 3.10.0- ...

  7. 手把手教你搭建Pytest+Allure2.X环境详细教程,生成让你一见钟情的测试报告(非常详细,非常实用)

    简介 宏哥之前在做接口自动化的时候,用的测试报告是HTMLTestRunner,虽说自定义模板后能满足基本诉求,但是仍显得不够档次,高端,大气,遂想用其他优秀的report框架替换之.一次偶然的机会, ...

  8. Redis数据库之经典考核习题

    Redis数据库之经典考核习题-题目 一.Redis数据库安装 要求每个学生首先对数据库进行安装,并最终能使用客产端进行数据库的登录. 二.数据库启动文件参数调整 假设数据库服务器默认端口6379已经 ...

  9. Spring 梳理-接收请求的输入(原)

    Spring MVC 允许一下方式将客户端的数据传送到控制器的处理方法中 查询参数(Query Parameter) 表单参数(Form  Parameter) 路径变量(Path  Variable ...

  10. 树上数据结构——LCT

    目录 树上数据结构--LCT 概述 基本概念 核心操作 其他操作 完整模板 树上数据结构--LCT 概述 LCT是一种强力的树上数据结构,支持以下操作: 链上求和 链上求最值 链上修改 子树修改 子树 ...