# codeforces-431C-k-Tree【dp】

479人阅读 评论(0)

## codeforces-431C-k-Tree【dp】

                time limit per test1 second     memory limit per test256 megabytes


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.

A 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: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).

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

input
3 3 2
output
3

input
3 3 3
output
1

input
4 3 2
output
6

input
4 5 2
output
7

//权值为i的处理所有情况

    dp[i][0] = dp[i][0] + dp[i - j][0]


//处理权值为i且存在边大于等于d的情况

        /* if (j >= d) dp[i][1] = dp[i][1] + dp[i - j ][0]

else dp[i][1] = dp[i][1] + dp[i - j ][1]        */

即：dp[i][1] = dp[i][1] + dp[i - j][j<d]


#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
int dp[105][105];
#define mod 1000000007
int main(){
int n,k,d;
cin >> n >> k >> d;
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= min(k,i); j++)
{
dp[i][0] = (dp[i][0] + dp[i - j][0]) % mod;
dp[i][1] = (dp[i][1] + dp[i - j][j<d]) % mod;
}
}
cout << (dp[n][1] % mod) << endl;
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：130175次
• 积分：4512
• 等级：
• 排名：第6582名
• 原创：328篇
• 转载：7篇
• 译文：0篇
• 评论：23条
关注博客
博客专栏
 ACM解题报告 文章：86篇 阅读：49300
阅读排行
最新评论