题目描述

The sum of the m-th powers of the first n integers

can be written as a polynomial of degree m + 1 in n:

For example:
S(n, 1) = (1 + . . . + n) = (1/2) ∗ n2+ (1/2) ∗ n
S(n, 2) = (1 + . . . + n2) = (1/3) ∗ n3+ (1/2) ∗ n2+ (1/6) ∗ n
S(n, 3) = (1 + . . . + n3) = (1/4) ∗ n4+ (1/2) ∗ n3) + (1/4) ∗ n2
S(n, 4) = (1 + . . . + n4) = (1/5) ∗ n5+ (1/2) ∗ n4) + (1/3) ∗ n3 − (1/30) ∗ n
The coefficients F(m, k) of these formulas form Faulhaber’s Triangle:
1
1/2 1/2
1/6 1/2 1/3
0 1/4 1/2 1/4
-1/30 0 1/3 1/2 1/5
0 -1/12 0 5/12 1/2 1/6
1/42 0 -1/6 0 1/2 1/2 1/7
where rows m start with 0 (at the top) and columns k go from 1 to m + 1
Each row of Faulhaber’s Triangle can be computed from the previous row by:
a) The element in row i and column j (j > 1) is (i/j) ∗ (theelementaboveleft); that is: F(i, j) =(i/j) ∗ F(i − 1, j − 1)
b) The first element in each row F(i, 1) is chosen so the sum of the elements in the row is 1.
Write a program to find entries in Faulhaber’s Triangle as decimal fractions in lowest terms .

输入

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set should be processed identically and independently.
Each data set consists of a single line of input consisting of three space separated decimal integers.
The first integer is the data set number. The second integer is row number m, and the third integer is the index k within the row of the entry for which you are to find F(m, k), the Faulhaber’s Triangle entry (0 ≤ m ≤ 400, 1 ≤ k ≤ m + 1).

输出

For each data set there is a single line of output. It contains the data set number, followed by a single space which is then followed by either the value if it is an integer OR by the numerator of the entry, a forward slash and the denominator of the entry.

样例输入

4
1 4 1
2 4 3
3 86 79
4 400 401

样例输出

1 -1/30
2 1/3
3 -22388337
4 1/401题目链接:点击查看

题目大意:给出公式:

  1. 当j!=1时,
  2. 当j==1时,

初始化F(0,1)=1,求指定位置的值

题目分析:这个题目给了很多无用的信息,但读懂需要打表后写一个函数打完表然后直接查询就行了,为了防止爆范围,我特地用了long long分别储存分子和分母,并写了一个化简函数,每次都除以两个数的gcd来约分,并且将分母上的符号转移到分子上方便输出,直接上代码吧,简单打表:

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;const int N=500;LL a[N][N],b[N][N];//分子,分母 void huajian(LL &a,LL &b)
{LL gcd=__gcd(a,b);a/=gcd;b/=gcd;if(a<0&&b<0)//如果都为负数,全部转正{a=-a;b=-b;}if(a>=0&&b<0)//如果符号在分母上,则转移到分子上{a=-a;b=-b;}
}void init()
{a[0][1]=1;b[0][1]=1;for(int i=1;i<=400;i++){LL suma=0;//suma和sumb储存第2~i+1列的值的总和LL sumb=1;//初始化为0/1(分数形式)for(int j=2;j<=i+1;j++){a[i][j]=i*a[i-1][j-1];b[i][j]=j*b[i-1][j-1];huajian(a[i][j],b[i][j]);LL tempa=suma*b[i][j]+sumb*a[i][j];//根据通分求和化简的LL tempb=sumb*b[i][j];huajian(tempa,tempb);suma=tempa;sumb=tempb;}a[i][1]=sumb-suma;//最后给F(i,1)赋值b[i][1]=sumb;huajian(a[i][1],b[i][1]);}
}int main()
{init();int w;cin>>w;while(w--){int num,x,y;scanf("%d%d%d",&num,&x,&y);printf("%d %lld",num,a[x][y]);if(b[x][y]!=1)printf("/%lld",b[x][y]);printf("\n");}return 0;
}

中石油训练赛 - Faulhaber’s Triangle(打表)相关推荐

  1. 中石油训练赛 - Trading Cards(最大权闭合子图)

    题目大意:给出 n 个卡片,可以自由买卖,且价格都是相同的,再给出 m 个集合,如果已经得到了其中一个集合中的卡片,那么可以获得该集合的收益,问如何操作可以使得收益最大化 题目分析:最大权闭合子图的模 ...

  2. 中石油训练赛 - Watch Later(状压dp)

    题目链接:点击查看 题目大意: 给出一个长度为 n 的字符串,字符串中共有 k 种不同的字符,现在问删除掉所有字符的最小操作数,对于每种字符需要确定一个先后顺序,每次需要删除掉当前所有的这种字符才能去 ...

  3. 中石油训练赛 - Swapping Places(字典序最小的拓扑排序)

    题目链接:点击查看 题目大意:给出 s 个字符串表示种类,再给出 m 个朋友关系,表示两个种类的动物是朋友,现在给出一个长度为 n 的种类排列,规定相邻两个是朋友的种类的动物可以交换位置,问如何操作, ...

  4. 中石油训练赛 - Gone Fishing(固定大小的圆可以覆盖最多的点)

    题目大意:在二维平面中给出 n 个点,再给出一个固定大小的圆,问如何放置这个圆可以使其覆盖最多的点 题目分析:首先不难想到一种 n^3 的做法,就是两层循环去枚举两个点,因为两个不同的点就可以确定下来 ...

  5. 中石油训练赛 - Russian Dolls on the Christmas Tree(树上启发式合并/主席树)

    题目链接:点击查看 题目大意:给出一棵 n 个节点的树,以点 1 为根,现在对于每个节点作为根的子树求解:子树中有多少个编号不相交的连续子段,如:1 2 4 5 7,共有三个连续的段,分别为 [ 1 ...

  6. 中石油训练赛 - Check List(线段树维护偏序问题)

    题目大意:给出 n 个点,需要计算出满足下列条件的三元对 ( i , j , k ) 的数量: x[ i ] < x[ j ] < x[ k ] y[ k ] > y[ i ] &g ...

  7. 中石油训练赛 - Bad Treap(数学)

    题目链接:点击查看 题目大意:给出笛卡尔树的定义,现在要求给出 n 个点对 ( x , sin( x ) ),使得笛卡尔树的高度尽可能大 题目分析:如果想让笛卡尔树的高度尽可能大,令其退化为一条链即可 ...

  8. 中石油训练赛 - High Load Database(二分+记忆化)

    题目链接:点击查看 题目大意:给出一个长度为 n 的数列,再给出 m 次询问,每次询问给出一个阈值 x ,问最少将数列分割成多少段,可以使得每一段的总和都不超过 x,无解的话输出 Impossible ...

  9. 中石油训练赛 - Plan B(点双缩点+树形dp)

    题目大意:给出一张 n 个点 m 条边的无向连通图,现在有某些点被标记了,问能否通过删除某个未被标记的点,使得删除该点后的数个互不相交的连通块中,至少存在一个联通块中不含有被标记的点 题目分析:首先不 ...

最新文章

  1. python编程怎么建立工程_教你如何用Python脚本快速创建项目
  2. WINCE6.0 chain.bin和xipkernel.bin解析
  3. PowerShell管理Azure
  4. iphone彻底删除照片如何恢复_手机删除的照片如何恢复?OPPO最新照片恢复
  5. Go 语言成为最受欢迎的语言
  6. ServletContext对象、ServletConfig对象
  7. Teradata在中国银行业的应用简介
  8. tperformancegraph_列车运行实绩图,train performance graph,音标,读音,翻译,英文例句,英语词典...
  9. 真正菜鸟用教程之WQSG Scrip Export WQSG (脚本导出导入工具,PSP、NDS汉化必备 )
  10. fh 幅频特性曲线怎么画fl_北京消防,关于消防图,你怎么看?
  11. wx2540h配置教程_H3C WX2540H系列无线控制器 安装指导-6W101
  12. 母婴行业竟也可以免费送?两种案例让你全面了解新的赚钱模式!
  13. 输入关键字生成对联_百度“智能春联”玩出新年味 输入关键词秒出春联
  14. 教师心理压力测试软件,关注教师心理健康——教师版心理测评软件
  15. JavaScript-歌词展示与音乐同步
  16. uniapp去掉返回键
  17. Python 实现三维姿态估计遮挡匹配预测
  18. 初探串口输出六轴陀螺仪
  19. 大学期末不挂科速成课-史上最全
  20. 基于一道例题进行QR分解三种方法的讲解:CGS算法,MGS算法,以及Householder算法的QR分解

热门文章

  1. 为什么需要两个Survivor区?
  2. 异常通知(After Throwing Advice)
  3. canal数据同步(客户端代码编写)
  4. OAuth2.0授权码认证流程介绍
  5. 反射_Class对象功能_获取Field
  6. RocketMQ的Producer详解之分布式事务消息(原理分析)
  7. 前端框架:发送请求获取数据的执行逻辑
  8. spring中bean的细节之三种创建Bean对象的方式
  9. php的常量和变量的区别,变量和常量的区别_在php当中常量和变量的区别
  10. sql相同顺序法和一次封锁法_率土之滨追击战法攻略