Rooks---LightOj1005 (permutation combination)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.