fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. vector<int> dp(1000000, -1);
  7.  
  8. int banyakcara(int N) {
  9. if (N == 0) {
  10. return 1;
  11. }
  12.  
  13. if (dp[N] != -1) {
  14. return dp[N];
  15. }
  16.  
  17. int cnt = 0;
  18. for (int i = 1; i <= 6; i++) {
  19. if (N - i >= 0) {
  20. cnt += banyakcara(N - i);
  21. }
  22. }
  23.  
  24. dp[N] = cnt;
  25. return cnt;
  26. }
  27.  
  28. int main() {
  29. int N;
  30. cin >> N;
  31.  
  32. cout << banyakcara(N);
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 6876KB
stdin
3
stdout
4