1
static int MOD = 1e9 + 7;6
// Total number of people who would have found out about the secret by the nth10
if (memo[n] != -1) // Return cached result if exists.12
// Current contribution of 1 person who knows the secret14
for (int i = delay; i < forget; i++) // Number of people that the secret will be forwarded to15
if (n - i >= 0) result = (result + dp(n - i)) % MOD;16
return memo[n] = result;18
int peopleAwareOfSecret(int n, int delay, int forget) {20
this->forget = forget;21
memo.resize(n + 1, -1);22
return (dp(n) - dp(n - forget) + MOD) % MOD; // Subtract the people who found out by the23
// `n-forget` day as observed.