组合数学,ans = C(n,k)*A(n,k).
#include#include #include #include #include #define LL long longusing namespace std;LL work(int n, int k){ if(k > n) return 0; LL sum1 = 1L, sum2 = 1L; for(int i = n;i > n-k;i --) sum1 = sum1*i; for(int i = 1;i <= k;i ++) sum2 = (sum2*(n-k+i))/i; return sum1*sum2;}int main(){ int n, k, t, CASE(0); scanf("%d", &t); while(t--) { scanf("%d%d", &n, &k); cout << "Case " << ++CASE << ": " << work(n, k) << endl; } return 0;}