HDU 4927 Series 1(大数+杨辉三角)
来源:互联网 发布:mac spss破解版 编辑:程序博客网 时间:2024/06/01 09:37
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.
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)
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
231 2 341 5 7 2
Sample Output
0-5
Author
BUPT
Source
2014 Multi-University Training Contest 6
题意:长为n的序列,进行n-1次操作:a[i+1]-a[i],输出最后得到的数
最后结果为:C(0,n-1)*a[n]-C(1,n-1)*a[n-1]+C(2,n-1)*a[n-2]......C(n-1,n-1)*a[1] 符号正负交替
另求解时可利用公式:C(k,n)=C(k-1,n)*(n-k+1)/k
import java.math.BigInteger;import java.util.Scanner;public class Main { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t>0) { t--; int n=in.nextInt(); BigInteger []a=new BigInteger[30005]; for(int i=0;i<n;i++) a[i]=in.nextBigInteger(); BigInteger ans=BigInteger.valueOf(0); BigInteger temp=BigInteger.valueOf(1); for(int i=0;i<n;i++) { ans=ans.add(temp.multiply(a[n-i-1])); temp=temp.multiply(BigInteger.valueOf(n-i-1)).divide(BigInteger.valueOf(i+1)).multiply(BigInteger.valueOf(-1)); } System.out.println(ans); } in.close(); }}
附:杨辉三角性质
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
1 10 45 120 210 252 210 120 45 10 1
前提:每行端点与结尾的数为1.
- 每个数等于它上方两数之和。
- 每行数字左右对称,由1开始逐渐变大。
- 第n行的数字有n项。
- 第n行数字和为2n-1。
- 第n行的m个数可表示为 C(n-1,m-1),即为从n-1个不同元素中取m-1个元素的组合数。
- 第n行的第m个数和第n-m+1个数相等 ,为组合数性质之一。
- 每个数字等于上一行的左右两个数字之和。可用此性质写出整个杨辉三角。即第n+1行的第i个数等于第n行的第i-1个数和第i个数之和,这也是组合数的性质之一。即 C(n+1,i)=C(n,i)+C(n,i-1)。
- (a+b)n的展开式中的各项系数依次对应杨辉三角的第(n+1)行中的每一项。
- 将第2n+1行第1个数,跟第2n+2行第3个数、第2n+3行第5个数……连成一线,这些数的和是第4n+1个斐波那契数;将第2n行第2个数(n>1),跟第2n-1行第4个数、第2n-2行第6个数……这些数之和是第4n-2个斐波那契数。
- 将各行数字相排列,可得11的n-1(n为行数)次方:1=11^0; 11=11^1; 121=11^2……当n>5时会不符合这一条性质,此时应把第n行的最右面的数字"1"放在个位,然后把左面的一个数字的个位对齐到十位... ...,以此类推,把空位用“0”补齐,然后把所有的数加起来,得到的数正好是11的n-1次方。以n=11为例,第十一行的数为:1,10,45,120,210,252,210,120,45,10,1,结果为 25937424601=1110。
阅读全文
0 0
- HDU 4927 Series 1(大数+杨辉三角)
- HDU 4927 Series 1(推理+大数)
- hdu 4927 Series 1(JAVA大数)
- hdu 4927 Series 1(组合,java大数)
- hdu 4927 Series 1 (大数模板加减乘除)
- hdu 4927 Series 1 大数,排列组合
- hdu 4927 Series 1 递推+大数
- HDU 4927 Series 1 java大数
- HDU 4927 Series 1 (大数高精度)
- hdu 4927 Series 1 组合数+大数+java
- hdu 4927 Series 1 (JAVA大数+二项式系数公式)
- HDU 4927 Series 1 杨辉三角形
- POJ 4927 Series 1 多校第六场 杨辉三角的应用
- HDU 4927 Series 1
- HDU 4927 Series 1
- HDU 4927 Series 1
- hdu 4927 Series 1
- hdu 4927 Series 1
- N
- 最大的问题是没有发现问题之一:谈谈滥用继承
- Android 多线程之可以重复启动与停止的服务
- vue.js笔记
- 将博客搬至CSDN
- HDU 4927 Series 1(大数+杨辉三角)
- 基于高德地图的地理编码
- 创建并运行maven项目
- [置顶] Android之基础建设之IWindow和IWindowSession
- [置顶] Android输入输出系统之TouchEvent流程
- 你所看到较轻松的Dagger2(基础介绍)
- 前沿技术:改良版的UDP协议QUIC将成为未来谷歌网站新标准
- [置顶] Android输入输出机制之来龙去脉之前生后世
- 标准库vector类型