Skip to content

Instantly share code, notes, and snippets.

@abiriadev
Created September 15, 2025 17:38
Show Gist options
  • Save abiriadev/f47ed6f9e245ec5b82a81442258ed1ce to your computer and use it in GitHub Desktop.
Save abiriadev/f47ed6f9e245ec5b82a81442258ed1ce to your computer and use it in GitHub Desktop.
const n = 10, s = 10
const x = s * n, m = s ** n
const dp = Array(n).fill(0).map(() => Array(x))
const ij = (i, j) => (i === -1 && j === -1 ? 1 : dp[i]?.[j] ?? 0)
for (let i = 0; i < n; ++i)
for (let j = i; j < x; ++j)
dp[i][j] = ij(i, j - 1) + ij(i - 1, j - 1) - ij(i - 1, j - (s + 1))
const p = dp[n - 1].map((c) => (c * c) / (m * m)).reduce((a, b) => a + b, 0)
console.log(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment