hdu4237 The Rascal Triangle 规律题

本文介绍了一种类似于帕斯卡三角形的Rascal三角形定义及其递推公式,并提供了一个高效的算法来计算特定位置的数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Rascal Triangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 64    Accepted Submission(s): 61


Problem 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 indicte the index m item in the index n row:
  
R(n,m) = 0 for n < 0 OR m < 0 OR m > n

The first and last numbers in each row(which are the same in the top row) are 1:
  
R(n,0) = R(n,n) = 1

The interior values are determined by (UpLeftEntry*UpRightEntry+1)/UpEntry(see the parallelogram in the array below):
  
R(n+1, m+1) = (R(n,m) * R(n,m+1) + 1)/R(n-1,m)


Write a program which computes R(n,m) theelement of therow of the Rascal Triangle.
 

Input
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 is a single line of input consisting of 3 space separated decimal integers. The first integer is data set number, N. The second integer is row number n, 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 (0 <= m <= n <= 50,000).
 

Output
For each data set there is onr line of output. It contains the data set number, N, followed by a single space which is then followed by thr Rascal Triangle entry R(n,m) accurate to the integer value.
 
5
1 4 0
2 4 2
3 45678 12345
4 12345 9876
5 34567 11398
 
 输出
5
1 4 0
2 4 2
3 45678 12345
4 12345 9876
5 34567 11398
 
题意
R(n+1, m+1) = (R(n,m) * R(n,m+1) + 1)/R(n-1,m)
R(n,0) = R(n,n) = 1
数塔从第0层开始  每层也是从0 开始
根据上面的2个式子推出来所有的
问输入 a b  输出第a行第b个数字
 
    0                                        1
    1                                     1     1
    2                                  1     2       1
    3                               1     3     3        1
    4                            1     4     5       4        1
    5                        1      5     7     7        5        1
    6                    1      6      9     10      9        6      1
 
 
 
可以看出第i行第j个满足 (i-j)*j+1;
规律找了好久 最终还是看人家的  看着我的队友10几分钟就看出来了 我真的感到好丢人啊
哎 只有努力了   抓紧时间搞下规律题
#include<stdio.h>
int main()
{
 int a,i,j,T,k;
 scanf("%d",&T);
 while(T--)
 {
  scanf("%d %d %d",&a,&i,&j);
  if(i==j||j==0)
   printf("%d %d\n",a,1);
        else 
        {            
   k= (i-j)*j+1;          
   printf("%d %d\n", a, k); 
        } 
    } 
    return 0; 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值