CF 108b Basketball team combinatorial Math

Source: Internet
Author: User

Test instructions

A university has m college, each college has SI individuals, now to form a team of n people, already know the hero in the first H college, and he was first accepted by the team, now the college in the remainder of the average probability of the selection of n-1 personal

Q: The hero wants to know if there are people in the team and he is from the same college, if not enough, then output-1

This is a simple combinatorial math problem, but be aware that the intermediate process of calculation overflows.

1#include <cstdio>2 3 Const intmaxn=1010;4 #defineLL Long Long5 6 intS[MAXN];7 8 intMain ()9 {Ten     intn,m,h; Onescanf"%d%d%d",&n,&m,&h); A     intsum=0; -      for(intI=1; i<=m;i++) -     { thescanf"%d",&s[i]); -sum+=S[i]; -     } -     if(sum<N) +     { -printf"-1\n"); +     } A     Else if(s[h]==1) at     { -printf"0\n"); -     } -     Else if(sum-s[h]<n-1) -     { -printf"1\n"); in     } -     Else to     { +s[h]--; -sum--; the         DoubleCnta=1; *          for(LL i=sum-s[h]-n+2; i<=sum-n+1; i++) $         {Panax Notoginsengcnta*=i; -         } the          for(LL i=sum-s[h]+1; i<=sum;i++) +         { Acnta=cnta/i; the         } +printf"%.6f\n",1.0-(Double) cnta); -     } $  $     return 0; -}
View Code

CF 108b Basketball team combinatorial Math

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.