-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKtreesdp.cpp
More file actions
57 lines (50 loc) · 914 Bytes
/
Ktreesdp.cpp
File metadata and controls
57 lines (50 loc) · 914 Bytes
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
#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;
ll n,k,d;
vector<vector<ll>> dp(200,vector<ll> (2,-1));
ll findPaths(ll pathSum,bool included)
{
if(pathSum > n)
return 0;
if(pathSum==n && included)
return 1;
if(pathSum==n && !included)
return 0;
ll a=(included)?1LL:0LL;
if(dp[pathSum][a]!=-1)
return dp[pathSum][a];
ll total=0LL;
for(ll i=1;i<=k;i++)
{
if(included)
{
total+=findPaths(pathSum+i,included);
}
else
{
if(i>=d)
{
total+=findPaths(pathSum+i,true);
}
else
total+=findPaths(pathSum+i,included);
}
}
// cout<<total;
return dp[pathSum][a]=total%MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
cin>>n>>k>>d;
cout<<findPaths(0,false)<<endl;
return 0;
}