Skip to content

Instantly share code, notes, and snippets.

@Superty
Last active September 11, 2016 20:29
Show Gist options
  • Save Superty/d8a2acf63ca1229f210e41f5bd5ef896 to your computer and use it in GitHub Desktop.
Save Superty/d8a2acf63ca1229f210e41f5bd5ef896 to your computer and use it in GitHub Desktop.
dp[i][j] = no. of ways to get j in the first i slots
dp[0][j] = 0, dp[0][0] = 1
dp[i][j] = sum[i - 1][b] - sum[(k = a to b)
sum[i - 1][j] = sum dp[i - 1][k] k = 1 to j
dp[i]
dp[i][j] = no. of ways to partition i into j partitions
dp[i][j] = dp[i - 1][j - 1] + j*dp[i - 1][j]
sum j*dp[i][j] =
sum dp[i][j] = sum dp[i - 1][j] (j = 0 to inf) + sum j*dp[i - 1][j] (j = 0 to inf)
= sum (j+1) dp[i - 1][j] (j = 0 to inf)
paste
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment