题目链接:HDU 4927 Series
题意:给出一串N个元素的序列,作为第一串序列,第二串序列是第二串序列相邻元素的查值(即Bi=Ai+1-Ai)...第三串....一直到第N-1串是序列中只有一个数。
刚开始想到模拟一发,WA了一把,推出公式,发现是二项展开的系数(正负交替)。组合数,果断要大数,苦逼JAVA不会。和一起队友摸索着,又T了一发,再想到组合数的递推。终于A了
C(a-1,b)=C(a,b)*a/(b-a+1)
AC代码:
import java.math.BigInteger;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
BigInteger a[] = new BigInteger[3010];
BigInteger sum = null, ans = null;
int t, n, i, flag;
t = cin.nextInt();
while (t > 0)
{
t = t - 1;
n = cin.nextInt();
for (i = 1; i <= n; i++)
a[i] = cin.nextBigInteger();
flag = 1;
sum = BigInteger.ZERO;
ans = BigInteger.ONE;
for (i = n; i >= 1; i--)
{
ans = ans.multiply(BigInteger.valueOf(i));
if (n - i != 0)
ans = ans.divide(BigInteger.valueOf(n - i));
else
ans = BigInteger.valueOf(1);
a[i] = a[i].multiply(ans);
if (flag == 1)
sum = sum.add(a[i]);
else
sum = sum.subtract(a[i]);
flag=flag^1;
}
System.out.println(sum);
}
}
}HDU 4927 Series (找规律+JAVA),布布扣,bubuko.com
原文地址:http://blog.csdn.net/u012377575/article/details/38440217