-
Notifications
You must be signed in to change notification settings - Fork 7
/
Codeforces-431C - k-Tree .cpp
64 lines (49 loc) · 1.14 KB
/
Codeforces-431C - k-Tree .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// Codeforces - C.k-Tree.
/// Category - Dp (coin change)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
const int mx=101;
ll tot[mx];
ll xtra[mx];
int main()
{
ll n,k,d;
cin>>n>>k>>d;
for(int i=1;i<=k;i++)
{
/// i<=k obviously
tot[i]=1ll;
/// i<d ,when
if(i<d) xtra[i]=1ll;
}
tot[0]=0;
xtra[0]=0;
/// how many ways we can build n by summing j
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
/// ignore this
if(i<j) continue;
tot[i]=(tot[i]+tot[i-j])%mod;
}
}
///how many ways we can build n by summing j,where j<d is true for all j
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
/// ignore this
if(i<j) continue;
/// j is less than d.
if(j<d) xtra[i]=(xtra[i]+xtra[i-j])%mod;
}
}
/// now,we can get the answer where number of ways
/// we can build n,where there at least one value is at least equal to d.
ll ans=(tot[n]-xtra[n]+mod)%mod;
cout<<ans<<endl;
return 0;
}