pid=4927">Series 1

大意:

题意不好翻译,英文看懂也不是非常麻烦,就不翻译了。

Problem Description
Let A be an integral series {A1, A2, . . . , An}.



The zero-order series of A is A itself.



The first-order series of A is {B1, B2, . . . , Bn-1},where Bi = Ai+1 - Ai.



The ith-order series of A is the first-order series of its (i - 1)th-order series (2<=i<=n - 1).



Obviously, the (n - 1)th-order series of A is a single integer. Given A, figure out that integer.
 
Input
The input consists of several test cases. The first line of input gives the number of test cases T (T<=10).



For each test case:

The first line contains a single integer n(1<=n<=3000), which denotes the length of series A.

The second line consists of n integers, describing A1, A2, . . . , An. (0<=Ai<=105)
 
Output
For each test case, output the required integer in a line.
 
Sample Input
2 3 1 2 3 4 1 5 7 2
 
Sample Output
0 -5
 
 
思路:
比赛中楠姐非常快就推出来公式了,想把杨辉三角预处理出来,然后发现BigInteger大小爆内存了。。

。非常无语

然后又想在暴力的基础上去优化。然后一直T到死。

。。 比赛结束也没搞出来。

赛后才知道。杨辉三角是能够直接用组合公式推出来的。。。
杨辉三角的第n行的第m个数为组合数c[n-1][m-1]。
应用c[n][m] = c[n][m-1]*(n-m+1)/m,就能够高速递推出第n行的数,这样既避免了打表会出现的爆内存。也省去了暴力好多的时间。。。。

还是太年轻  哎。。。


	import java.io.*;
import java.math.*;
import java.util.*;
public class Main { static BigInteger coe[][] = new BigInteger [3010][3010];
public static void main(String[] args) throws IOException{
Scanner cin = new Scanner(System.in);
BigInteger []a = new BigInteger[3010];
BigInteger []c = new BigInteger[3010];
int T;
T = cin.nextInt();
while(T-- > 0){
int n;
n = cin.nextInt();
for(int i = 1; i <= n; ++i){
a[i] = cin.nextBigInteger();
}
BigInteger ans = BigInteger.ZERO;
c[0] = BigInteger.ONE;
ans = ans.add(c[0].multiply(a[n]));
int t = -1;
for(int i = 1; i < n; ++i){
BigInteger t1 = BigInteger.valueOf(n).subtract(BigInteger.valueOf(i));
BigInteger t2 = BigInteger.valueOf(i);
c[i] = c[i-1].multiply(t1).divide(t2);
ans = ans.add(c[i].multiply(a[n-i]).multiply(BigInteger.valueOf(t)));
t *= -1;
}
System.out.println(ans);
} }
}

HDU 4927 Series 1 ( 组合+高精度)的更多相关文章

  1. HDU 4927 Series 1(高精度+杨辉三角)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4927 解题报告:对于n,结果如下: C(0,n-1) *A[n] - C(1,n-1) * A[n-1 ...

  2. HDU 4927 Series 1(推理+大数)

    HDU 4927 Series 1 题目链接 题意:给定一个序列,要求不断求差值序列.直到剩一个,输出这个数字 思路:因为有高精度一步.所以要推理一下公式,事实上纸上模拟一下非常easy推出公式就是一 ...

  3. 2014多校第六场 1007 || HDU 4927 Series 1(杨辉三角组合数)

    题目链接 题意 : n个数,每操作一次就变成n-1个数,最后变成一个数,输出这个数,操作是指后一个数减前一个数得到的数写下来. 思路 : 找出几个数,算得时候先不要算出来,用式子代替,例如: 1 2 ...

  4. 多校第六场 HDU 4927 JAVA大数类+模拟

    HDU 4927 −ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊.如今对组合算比較什么了-- import java ...

  5. hdu 4927 组合+公式

    http://acm.hdu.edu.cn/showproblem.php?pid=4927 给定一个长度为n的序列a,每次生成一个新的序列,长度为n-1,新序列b中bi=ai+1−ai,直到序列长度 ...

  6. 【HDU - 4927】Series 1

    BUPT2017 wintertraining(15) #5I 题意 输出序列A[1..n]的第n-1阶差分(一个整数). 题解 观察可知答案就是 \[ \sum_{i=0}^{n-1} {(-1)^ ...

  7. HDU 4927

    http://acm.hdu.edu.cn/showproblem.php?pid=4927 直接模拟会超时,要在纸上写写推公式 A[n]*C(0,n-1)  - A[n-1]*C(1,n-1) + ...

  8. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  9. hdu 1715 大菲波数(高精度数)

    Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值. Inpu ...

随机推荐

  1. Two PWM outputs from MCU combine to form a monotonic 16-bits DAC

    http://www.edn.com/design/analog/4329365/Combine-two-8-bit-outputs-to-make-one-16-bit-DAC

  2. 将dll文件注入到其他进程中的一种新方法

    http://www.45it.com/windowszh/201212/33946.htm http://www.hx95.cn/Article/OS/201212/65095.html 我们知道将 ...

  3. crtmpserver配置文件详解

    Configuration file配置文件 The configuration file is actually a lua script which must contain an object ...

  4. Linux使用RPM安装软件

    什么是RMP? RPM 的为Redhat Package Manager (RPM软件包管理器)的缩写. RPM包,这种软件包就像windows的EXE安装文件一样,各种文件已经编译好,并打了包,哪个 ...

  5. 7)Linux程序设计入门--网络编程

    )Linux程序设计入门--网络编程 Linux系统的一个主要特点是他的网络功能非常强大.随着网络的日益普及,基于网络的 应用也将越来越多. 在这个网络时代,掌握了Linux的网络编程技术,将令每一个 ...

  6. HDU 3949 XOR 高斯消元

    题目大意:给定一个数组,求这些数组通过异或能得到的数中的第k小是多少 首先高斯消元求出线性基,然后将k依照二进制拆分就可以 注意当高斯消元结束后若末尾有0则第1小是0 特判一下然后k-- 然后HDU输 ...

  7. UTC 转本地时间

    String dateStr = "Wed Dec 10 00:00:00 UTC 0800 2014"; //Wed Dec 10 00:00:00 UTC 0800 2014 ...

  8. CSS3 Media Queries 详细介绍与使用方法[转]

    Media Queries 就是要在支援CSS3 的浏览器中才能正常工作,IE8 以下不支援. 而Media Queries 的套用方法千变万化,要套用在什么样的装置中,都可以自己来定义. 关于Med ...

  9. Javascript屏蔽鼠标右键-超简单,不过还是记录一下

    Javascript屏蔽鼠标右键,其实作用也不大,也许是为了防止别人查看源代码,其实想查看源代码有多种途径,未必需要通过鼠标右键.不过当我们自定义鼠标右键弹出菜单时,也许需要这些. 下面是源码: 1 ...

  10. Visual Studio 2015年预览设置: 辅助安装程序说明

    本文介绍了第三方应用程序安装辅助安装的 Visual Studio 2015年预览时安装的说明.如果您安装了多设备开发功能,您需要使用其他第三方软件来处理这些项目.辅助安装程序允许您将部署到您的计算机 ...