Title Link: http://lightoj.com/volume_showproblem.php?problem=1005
Test instructions is in a n*n square put K chess pieces, each row each column can not have two pieces, ask how many methods, and 8 queen question very much like, but 8 queen problem can use violent search, but the value range of the subject n is large, can not use search; I found the formula at the game, However, due to the multiplication order problem caused by the error, is A (n,k) *a (n,k)/A (k,k), i.e. C (n, k) *a (n, k);
#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespacestd;#defineN 4000100intMain () {intT, t=1; intN, M; Long Longans; scanf ("%d", &T); while(t--) {scanf ("%d%d", &n, &m); Ans=1; for(intI=n; i>n-m; i--) ans*=i; for(intI=1; i<=m; i++) ans/=i; for(intJ=m; i>n-m; i--) ans*=i; printf ("Case %d:%lld\n", t++, ans); } return 0;}
View Code
Another method is DP:
Don't put it up first ...
Rooks---LightOj1005 (permutation combination)