fork download
  1. // C++ Program for the above approach
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. // Function to calculate the total
  7. // number of ways to have sum N
  8. void findWays(int N)
  9. {
  10. // Initialize dp array
  11. int dp[N + 1];
  12.  
  13. dp[0] = 1;
  14.  
  15. // Iterate over all the possible
  16. // intermediate values to reach N
  17. for (int i = 1; i <= N; i++) {
  18.  
  19. dp[i] = 0;
  20.  
  21. // Calculate the sum for
  22. // all 6 faces
  23. for (int j = 1; j <= 6; j++) {
  24.  
  25. if (i - j >= 0) {
  26. dp[i] = (dp[i] + dp[i - j]) % 1000000007 ;
  27. }
  28. }
  29. }
  30.  
  31. // Print the total number of ways
  32. cout << dp[N];
  33. }
  34.  
  35. // Driver Code
  36. int main()
  37. {
  38. // Given sum N
  39. int N = 7;
  40.  
  41. // Function call
  42. findWays(N);
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5380KB
stdin
Standard input is empty
stdout
63