hdu 4927 java程式

來源:互聯網
上載者:User

標籤:integer   name   方便   stat   []   valueof   content   實用   else   

/*對於本題題意非常easy關鍵在於求楊輝三角時的二項式是沒實用到最佳化,導致逾時。

對於第n行的二項式的第i個可有第i-1個乘於一個數處於一個數得到,要用到大數。java比較方便。假如n=6,i=4;C(n,i)=C(n,i-1)*(n-i+1)/i;*/import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[] args) { int i,j, e,ee,n,s,t; BigInteger f[]=new BigInteger[3100],h[]=new BigInteger[3100],ans,ff,flag,p; Scanner cin = new Scanner (System.in); int k=cin.nextInt(); boolean d=true; while(d) { ans=BigInteger.valueOf(0); n= cin.nextInt(); for(i=1; i<=n; i++) f[i]=cin.nextBigInteger(); h[1]=BigInteger.valueOf(1); for(i=2; i<=n; i++) { e=i-1; ee=n-i+1; flag=BigInteger.valueOf(e); p=BigInteger.valueOf(ee); h[i]=h[i-1].multiply(p); h[i]=h[i].divide(flag); } for(i=1; i<=n; i++) { if(i%2!=n%2) { p=BigInteger.valueOf(-1); p=h[i].multiply(p); f[i]=f[i].multiply(p); ans=ans.add(f[i]); } else { f[i]=f[i].multiply(h[i]); ans=ans.add(f[i]); } } System.out.println(ans); k=k-1; if(k==0) d=false; } }}


hdu 4927 java程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.