Codeforces Round #247 (Div. 2)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mystery_guest/article/details/70225541

C. k-Tree
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Examples
input
3 3 2
output
3
input
3 3 3
output
1
input
4 3 2
output
6
input
4 5 2
output
7
dp好题!

和bjfuoj的Frozen口袋类似,二维dp,dp[i][j],i存到和,j==0时,表示到i为止,还没出现过>=d的数,反之,j==1时,则出现过。

记住%1e9+7。。。开了long long。

然后每层dp一下,状态转移为:

if(j>=d)

dp[i][1]=(dp[i][1]+dp[i-j][0]+dp[i-j][1])%mod

else

{

dp[i][0]=(dp[i][0]+dp[i-j][0])%mod

dp[i][1]=(dp[i][1]+dp[i-j][1])%mod

}

我们需要把dp[i][0]放在else里面,防止重复计数。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#define eps 1e-8
#define zero(x) (((x>0?(x):-(x))-eps)
#define mem(a,b) memset(a,b,sizeof(a))
#define memmax(a) memset(a,0x3f,sizeof(a))
#define pfn printf("\n")
#define ll __int64
#define ull unsigned long long
#define sf(a) scanf("%d",&a)
#define sf64(a) scanf("%I64d",&a)
#define sf264(a,b) scanf("%I64d%I64d",&a,&b)
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define sf464(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define sf564(a,b,c,d,ee) scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&ee)
#define sf2(a,b) scanf("%d%d",&a,&b)
#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sf5(a,b,c,d,ee) scanf("%d%d%d%d%d",&a,&b,&c,&d,&ee)
#define sff(a) scanf("%f",&a)
#define sfs(a) scanf("%s",a)
#define sfs2(a,b) scanf("%s%s",a,b)
#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)
#define sfd(a) scanf("%lf",&a)
#define sfd2(a,b) scanf("%lf%lf",&a,&b)
#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)
#define sfc(a) scanf("%c",&a)
#define ull unsigned long long
#define pp pair<int,int>
#define debug printf("***\n")
#define pi 3.1415927
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> inline T Min(T a, T b) { return a < b ? a : b; }
template<class T> inline T Max(T a, T b) { return a > b ? a : b; }
bool cmpbig(int a, int b){ return a>b; }
bool cmpsmall(int a, int b){ return a<b; }
using namespace std;
int main()
{
    //freopen("data.in","r",stdin);
    //freopen("data.out" ,"w",stdout);
    int n,k,d;
    while(~sf3(n,k,d))
    {
        ll dp[110][2];
        mem(dp,0);
        dp[0][0]=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=min(k,i);j++)
            {
                if(j>=d)
                    dp[i][1]=(dp[i][1]+dp[i-j][0]+dp[i-j][1])%mod;
                else
                {
                    dp[i][1]=(dp[i][1]+dp[i-j][1])%mod;
                    dp[i][0]=(dp[i][0]+dp[i-j][0])%mod;
                }
            }
        }
        printf("%d\n",dp[n][1]%mod);
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/mystery_guest/article/details/70225541