fork(1) download
  1. //CF K-Tree
  2. #include <iostream>
  3. using namespace std;
  4. #define MOD 1000000007
  5. long long dp[104][2];
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. long n,k,d;
  12. cin>>n>>k>>d;
  13. for(int i=0; i<=100; i++)
  14. dp[i][0]=dp[i][1]=0;
  15. dp[0][0]=1;
  16. for(int s=1; s<=n; s++)
  17. {
  18. for(int i=(s-1); i>=(s-d+1) && i>=0; i--)
  19. {
  20. dp[s][0]=(dp[s][0]+dp[i][0])%MOD;
  21. dp[s][1]=(dp[s][1]+dp[i][1])%MOD;
  22. }
  23. for(int i=(s-d); i>=(s-k) && i>=0; i--)
  24. dp[s][1]=(dp[s][1]+dp[i][0]+dp[i][1])%MOD;
  25. }
  26. cout<<dp[n][1];
  27. }
  28.  
  29. //You need to change the 'int' dp[104][2] to 'long long' dp[104][2]. This is because the temporary result stored in dp[i][k] is of data type int which overflows and hence wraps around to give negative results and hence wrong answer.
Success #stdin #stdout 0s 3452KB
stdin
3 3 2
stdout
3