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行的数,这样既避免了打表会出现的爆内存。也省去了暴力好多的时间。。。。

还是太年轻  哎。。。


  1. import java.io.*;
  2. import java.math.*;
  3. import java.util.*;
  4. public class Main {
  5.  
  6. static BigInteger coe[][] = new BigInteger [3010][3010];
  7. public static void main(String[] args) throws IOException{
  8. Scanner cin = new Scanner(System.in);
  9. BigInteger []a = new BigInteger[3010];
  10. BigInteger []c = new BigInteger[3010];
  11. int T;
  12. T = cin.nextInt();
  13. while(T-- > 0){
  14. int n;
  15. n = cin.nextInt();
  16. for(int i = 1; i <= n; ++i){
  17. a[i] = cin.nextBigInteger();
  18. }
  19. BigInteger ans = BigInteger.ZERO;
  20. c[0] = BigInteger.ONE;
  21. ans = ans.add(c[0].multiply(a[n]));
  22. int t = -1;
  23. for(int i = 1; i < n; ++i){
  24. BigInteger t1 = BigInteger.valueOf(n).subtract(BigInteger.valueOf(i));
  25. BigInteger t2 = BigInteger.valueOf(i);
  26. c[i] = c[i-1].multiply(t1).divide(t2);
  27. ans = ans.add(c[i].multiply(a[n-i]).multiply(BigInteger.valueOf(t)));
  28. t *= -1;
  29. }
  30. System.out.println(ans);
  31. }
  32.  
  33. }
  34. }

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. SEAndroid安全机制简要介绍和学习计划

    与iOS相比.Android最被人诟病的是其流畅性和安全性. 然而,从4.0開始,Android不遗余力地改善其流畅性. 特别是在即将公布的L版本号中,用ART替换了Dalvik,相信会越来越流畅.至 ...

  2. WPF ClickOnce应用程序IIS部署发布攻略

    WPF程序非常适合公司内网使用,唯一缺点就是客户端要安装.net框架4.0.优势也很明显,在客户端运行的是一个WinForm程序,自动下载,可以充分利用客户机的性能,而且是以当前的Windows用户权 ...

  3. Android BottomNavigationBar底部导航控制器的使用

    最近Google在自己推出的Material design中增加了Bottom Navigation导航控制.Android一直没有官方的导航控制器,自己实现确实是五花八门,有了这个规定之后,就类似苹 ...

  4. Java 3D游戏引擎——JME(java Monkey Engine)

    转自:http://bbs.gameres.com/forum.php?mod=viewthread&tid=180732 JME(java Monkey Engine),一个非常棒的Java ...

  5. UIControl的子类UISwitch, UISegmentedCntrol, UIPageControl详解

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

  6. HttpClient使用例子

    HttpClient client = new HttpClient(); String url = http://localhost:8080/ana/workFlowOaInterface.do? ...

  7. android基础学习-Fragment和eclipse快捷键

    使用Fragment的原因 1. Activity间的切换不流畅 2. 模块化Activity,方便做局部动画(有时为了到达这一点要把多个布局放到一个activity里面,现在可以用多Fragment ...

  8. T-sql 根据bak文件恢复新建数据库

    利用bak文件恢复新建数据库: 1:利用sqlserver界面管理工具恢复,在操作2005以上的版本可以讲界面的操作过程生成sql语句(本人在此徘徊了好久,得一位博友提醒才恍然大悟); 2:利用sql ...

  9. 【Android UI】使用RelativeLayout与TableLayout实现登录界面

    使用RelativeLayout与TableLayout分别实现两种登录界面,学习RelativeLayout布局 中如何对齐与调整组件相对位置,使用TableLayout实现登录界面,学习如何设置列 ...

  10. CUDA,cudnn一些常见版本问题

    - 最好的方法是官网说明: https://tensorflow.google.cn/install/source_windows Version Python version Compiler Bu ...