LightOj 1005 (Rooks)
#lightoj #cp #problem_solving #recursion #combinatorics
Idea 1
- Put a rook in row 1 , so there are c ways (c columns) to do that
c * solve(r-1,c-1,k-1)
- and don’t put a rook in row 1 , so there are r-1 rows
solve(r-1,c,k)
- So ,
ans = c * solve(r-1,c-1,k-1) + solve(r-1,c,k)
Idea 2
- take
k
row fromn
row =nCk
- take
k
col fromn
col =nCk
- how many ways
k
rook arrange among themselves =k!
ans = nCk * nCk * k!
comb[n][k] = comb[n-1][k] + comb[n-1][k-1]
1 |
|