You are viewing a single comment's thread. Return to all comments →
Actually the answer is
(m+n-1)C(n)=(m+n-1)!/ ((m-1)!)*n!)
and the forumula
Ncr=(n-1)c(r-1)+ (n-1)c(r)
now you can apply dp you may take help of this function as it is little bit tuff for me to understand c# that's why iam writing this function
`cpp
for (i = 0; i <= n; i++) { for (j = 0; j <= k; j++) {
if (j == 0 || j == i)//as nc0=ncn=1; C[i][j] = 1; else C[i][j] = ((C[i-1][j-1])%mod +( C[i-1][j])%mod)%mod; } }
`
now you can return the desired answer .
Now in your code this line
result = (topfact / (belowfact1 * belowfact2))%1000000007; will get run-time error or tle as your modulus approach formula is not correct as
(a * b) % mod = ((a % mod) * (b % mod)) % mod, (a / b ) % mod = ((a % mod) * (b^-1 % mod)) % mod,
and one more reason is that the
(topfact / (belowfact1*belowfact2))
will not work properly .
if problem persist then feel free to contact for further
clarification or you may take help of my c code
http://ideone.com/knhd1k
....
Sherlock and Permutations
You are viewing a single comment's thread. Return to all comments →
Actually the answer is
(m+n-1)C(n)=(m+n-1)!/ ((m-1)!)*n!)
and the forumula
Ncr=(n-1)c(r-1)+ (n-1)c(r)
now you can apply dp you may take help of this function as it is little bit tuff for me to understand c# that's why iam writing this function
`cpp
for (i = 0; i <= n; i++) { for (j = 0; j <= k; j++) {
`
now you can return the desired answer .
Now in your code this line
result = (topfact / (belowfact1 * belowfact2))%1000000007; will get run-time error or tle as your modulus approach formula is not correct as
(a * b) % mod = ((a % mod) * (b % mod)) % mod, (a / b ) % mod = ((a % mod) * (b^-1 % mod)) % mod,
and one more reason is that the
(topfact / (belowfact1*belowfact2))
will not work properly .
if problem persist then feel free to contact for further
clarification or you may take help of my c code
http://ideone.com/knhd1k
....