/**
大意 : 求1^m + 2^m + 3^m + 4^m +....+ n^m
解题步骤:
先构造从0到m的第1阶差分序列,然后以下所有2----》p阶的差分表。
令C[n+1][1]=n,用递推构造C[n+1][1]~C[n+1][p+1]的组合数打个一维表;
最后利用C0*C[1]+C1*C[2]+...+Cp*C[p+1]得出答案...
注意: java 提交时,一定要将包名去掉,,并且类名为Main
这一题就是因为多加了个包名,,一直是 runtime error。。一个多小时。。血的教训啊。。 **/ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner; public class Main { static BigInteger h[][] = new BigInteger [][];
static BigInteger []c = new BigInteger [];
public static void getc(BigInteger n,int m){
c[] =n;
for(int i= ; i<=m+ ; i++ ){
c[i]= c[i-].multiply(n.subtract(BigInteger.valueOf(i-))).divide(BigInteger. valueOf(i));
} } public static void main(String[] args) {
Scanner cin = new Scanner(System. in);
int t = cin.nextInt();
while(t-->){
BigInteger n = cin.nextBigInteger().add(BigInteger. ONE);
int m = cin.nextInt();
for(int i=; i<=m;i++)
h[][i] = BigInteger. valueOf(i).pow(m); for(int i=;i<=m;i++){
for(int j=;j<=m-i;j++){
h[i][j] = h[i-][j+].subtract( h[i-][j]);
}
}
BigInteger ans = BigInteger. ZERO;
getc(n,m);
for(int i=;i<=m;i++){
ans = ans.add( h[i][].multiply( c[i+]));
}
System. out.println(ans);
} } }

poj 2515 Birthday Cake的更多相关文章

  1. POJ 1020 Anniversary Cake(DFS)

    Anniversary Cake Time Limit: 1000MSMemory Limit: 10000KB64bit IO Format: %I64d & %I64u Submit St ...

  2. poj 1020 Anniversary Cake(切正方形蛋糕+搜索)

                                                                                                         ...

  3. poj 2515 差分序列,排列组合

    大神博客链接 http://blog.csdn.net/kksleric/article/details/8021276 这道题的差分序列从没看过,公式题. 先构造从0到m的第p阶差分序列,算出0^p ...

  4. poj 3743 LL’s cake (PSLG,Accepted)

    3743 -- LL’s cake 搞了好久都过不了,看了下题解是用PSLG来做的.POJ 2164 && LA 3218 Find the Border (Geometry, PSL ...

  5. POJ 3743 LL’s cake(圆+PSLG)

    题意是给你一块在原点半径为10的圆,然后告诉你一条直线在圆弧上的极角,相当于用这条直线把这个圆分成两半,然后一共是n条直线切圆,就好比切蛋糕,问你其中最大一块的面积是多少. 如果我们将圆弧转化成直线边 ...

  6. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

  7. [转] POJ数学问题

    转自:http://blog.sina.com.cn/s/blog_6635898a0100magq.html 1.burnside定理,polya计数法 这个大家可以看brudildi的<组合 ...

  8. poj 1419 Graph Coloring

    http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还 ...

  9. POJ1020 Anniversary Cake

    题目来源:http://poj.org/problem?id=1020 题目大意:有一块边长为s的正方形大蛋糕,有n个客人,每个客人想分一块边长为si的正方形蛋糕.求这块大蛋糕能否恰好满足所有客人的需 ...

随机推荐

  1. Android发展简单介绍

    Android一词的本义指“机器人”,同一时候也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件.用户界面和应用软件组成,号称是首个为移动 ...

  2. [Ext JS 4] 布局之实战一 - 中间区块不会自动伸展 (tab)

    前言 [Ext JS 4] 布局之实战一 - 中间区块不会自动伸展 (tab) 在上一篇中,中间的tab 区块无法自动伸展的原因一句话说就是: 使用contentEL的方式,相关HTML元素不会参与组 ...

  3. Libcurl安装及编译

    1.安装curl wget http://curl.haxx.se/download/curl-7.26.0.tar.gz tar -zxvf curl-7.26.0.tar.gz  cd curl- ...

  4. c 结构体struct

    struct 定义初始化 #include<stdio.h> typedef struct stuInfo { ]; //姓名 int stuId; //学号 int age; //年龄 ...

  5. Echarts数据图表插件--开源、大气、强大

    个人觉得不错,分享给大家. 教程地址:http://echarts.baidu.com/, 开源项目:https://github.com/ecomfe/echarts

  6. ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'information_schema'

    在我想把备份的数据库导入到本地数据的时候,发生这个错误,我使用的工具是dbForge Studio for MySQL ERROR 1044 (42000): Access denied for us ...

  7. 利用python进行数据分析之数据聚合和分组运算

    对数据集进行分组并对各分组应用函数是数据分析中的重要环节. group by技术 pandas对象中的数据会根据你所提供的一个或多个键被拆分为多组,拆分操作是在对象的特定轴上执行的,然后将一个函数应用 ...

  8. linux(ubuntu) 遇到的问题 --1

    1.使用sudo提示用户不在sudoers文件中的解决方法 切换到root用户 su root 查看/etc/sudoers文件权限,如果只读权限,修改为可写权限 [root@localhost ~] ...

  9. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  10. 3_Guess Fingers

    3 // // ViewController.swift // Guess Fingers // // Created by ZC on 16/1/8. // Copyright © 2016年 ZC ...