HDU_4237_The Rascal Triangle(推公式)
来源:互联网 发布:时时彩后一必中 软件 编辑:程序博客网 时间:2024/05/09 16:48
Description
The Rascal Triangle definition is similar to that of the Pascal Triangle. The rows are numbered from the top starting with 0. Each row n contains n + 1 numbers indexed from 0 to n. Using R(n, m) to indicate the index m item in the index n row:
The first and last numbers in each row (which are the same in the top row) are 1:
The interior values are determined by (UpLeftEntry*UpRightEntry + 1)/UpEntry (see the parallelogram in the array below):
Write a program which computes R(n, m) the m-th element of the n-th row of the Rascal Triangle.
Input
The first line of input contains a single integer P, ( 1P1000), which is the number of data sets that follow. Each data set is a single line of input consisting of 3 spaces separated decimal integers. The first integer is data set number, N. The second integer is row numbern, and the third integer is the index m within the row of the entry for which you are to find R(n, m) the Rascal Triangle entry ( 0mn50000).
Output
For each data set there is one line of output. It contains the data set number, N, followed by a single space which is then followed by theRascal Triangle entry R(n, m) accurate to the nearest integer value.
Sample Input
51 4 02 4 23 45678 123454 12345 98765 34567 11398
Sample Output
1 12 53 4114958864 243838455 264080263
题型:找规律
题意:给出一个类似于杨辉三角的数塔,最左端和最右端都是1,递推式为
R(n + 1, m + 1) = (R(n, m)*R(n, m + 1) + 1)/R(n - 1, m)
就是这个数等于其上面两个数的积再加1再除以其上面的上面的那个数,for example :(3*3+1)/ 2 = 5。
求出第n行第m个数是什么。
分析:根据递推式来写代码是不能的,会超时。直接求出一个式子直接用就可以了,代码及其简短。
代码:
#include<iostream>#include<cstdio>using namespace std;int main(){int t,r;long long n,m,k;scanf("%d",&t);while(t--){scanf("%d%lld%lld",&r,&k,&m);printf("%d %lld\n",r,1+(k-m)*m);}return 0;}
- HDU_4237_The Rascal Triangle(推公式)
- HDU4237:The Rascal Triangle
- The Rascal Triangle
- The Rascal Triangle 题解
- HDU4237 The Rascal Triangle
- hdu4237 The Rascal Triangle 规律题
- CF 336A(Vasily the Bear and Triangle-推公式)
- 推公式。。
- POJ 3012 : A Number from Yanghui Triangle - 快速幂;推公式
- HDU2552 推公式||用公式
- POJ 3734 推公式
- 推公式+二分--poj1759
- hdu2047-递推公式
- HDU_5047_Sawtooth(推公式+高精度)
- 数学推公式题
- HDU 3490 推公式
- ZJNU 1265 推公式
- SPOJ VECTAR5 推公式
- DFS算法
- JDBC连结中Class.forName()详解
- 报表运行时的报表合并
- 运输层
- 【学习笔记】WIN7系统下利用自带IIS配置服务器
- HDU_4237_The Rascal Triangle(推公式)
- 【UltraISO+U盘+win8重装系统】
- 关键词和描述标签
- 黑马程序员-抽象类,接口和内部类
- 多吃防晒食物 肌肤白皙年轻
- vi 中16进制显示二进制文件
- 浅谈构造函数&析构函数
- 新站如何做好内容和外链
- 多校联合 Park Visit (求树的最长路径)