Series 1 Java second number of combinations

Source: Internet
Author: User

                        Series 1

As a couple of examples, it is easy to think of a combination of C (n,m) ==c[n,n-m), which is the middle symmetry of the coefficients. This problem is the high-precision combinatorial number, Java seconds.

TIME:1825MS, close to the time limit, and if n is slightly larger, time out.

1 Importjava.math.*;2 ImportJava.util.*;3 ImportJava.io.*;4 Importjava.text.*;5 6  Public classMain7 {8     Static intms=3005;9      Public Static voidMain (string[] args)Ten     { OneScanner cin=NewScanner (NewBufferedinputstream (system.in)); A         int[] A=New int[MS]; -         intT,n; -t=cin.nextint (); the          while(t-->0) -         { -n=cin.nextint (); -              for(inti=0;i<n;i++) +a[i]=cin.nextint (); -BigInteger ans=biginteger.valueof (a[n-1]); +BigInteger res=Biginteger.one; ABigInteger flag=biginteger.valueof (-1); atBigInteger t=Biginteger.one; -N=n-1; -              for(inti=1,j=n;i<=n;i++,j--) -             { -res=res.multiply (Biginteger.valueof (j)). Divide (biginteger.valueof (i)); -T=res.multiply (flag) Multiply (biginteger.valueof (a[j-1])); inFlag=flag.multiply (biginteger.valueof (-1)); -ans=Ans.add (t); to             } + System.out.println (ans); -         } the cin.close (); *     } $}

Series 1 Java second number of combinations

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.