Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef long long ll;
- const int MOD = 1e9 + 7;
- int n;
- int dp[1000005];
- int rec(int suma) {
- if(suma == n) {
- return 1;
- }
- if(dp[suma] != -1) {
- return dp[suma];
- }
- int result = 0;
- for(int i = 1; i <= 6; i++) {
- if(suma + i <= n) {
- result += rec(suma + i);
- result %= MOD;
- }
- }
- return dp[suma] = result;
- }
- int main() {
- memset(dp, -1, sizeof dp);
- cin >> n;
- cout << rec(0) << endl;
- return 0;
- }
- // rec(0) = rec(1) + rec(2) + rec(3) = 2 + 1 + 1 = 4
- // rec(1) = rec(2) + rec(3) = 1 + 1 = 2
- // rec(2) = rec(3) = 1
- // rec(3) = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement