Codeforces Round #247 (Div. 2)C. k-Tree(动态规划)

传送门

Description

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-tree.

k-tree is an infinite rooted tree where:

  • each vertex has exactly k children;
  • each edge has some weight;
  • if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 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 (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".

Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7).

Input

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

Output

Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Sample Input

3 3 2

3 3 3

4 3 2

4 5 2

Sample Output

3

1

6

7

思路

题意:

 给定一个k叉树,并且边的权重为1,2,...,k,问有多少条路径,使得路径上的边的权重之和为n,并且这条路径上至少存在一条边其权重不小于d。

题解:

首先考虑有多少条路径,其权重之和为n,用dp[n]代表权重和为n的方案,那么由于是k叉树,那么dp[n] = dp[n - 1] + dp[n - 2] + ... + dp[n - k];现在考虑路径上至少有一条边权重不小于d的情况,用dp[n][1]代表权重之和为1且存在至少一条边不小于d的方案数,那么dp[n][0]代表权重之和为n且路径上每一条边都小于d的方案数。所以当前权重为x时,继续下一步,那么选择的边权为y的分支时,转移方程:当y < d dp[x + y][0] += dp[x][0] 否则dp[x + y][1] += dp[x][0],不管y 是否大于 d,都有dp[x + y][1] += dp[x][1];

 

  

  

 

posted @   zxzhang  阅读(371)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示

目录导航