标签:blog java io for 2014 ar div new
/*对于本题题意很简单 关键在于求杨辉三角时的二项式是没有用到优化,导致超时。对于第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程序,布布扣,bubuko.com
标签:blog java io for 2014 ar div new
原文地址:http://blog.csdn.net/u011483306/article/details/38458523