22743_TheRascalTriangle

2022-5-16 18:22| 发布者: Hocassian| 查看: 32| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506915238299-Problem List-采集的数据-后羿采集器.html

Pro.ID

22743

Title

The Rascal Triangle

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22743

AC

13

Submit

21

Ratio

61.90%

时间&空间限制

  • Time Limit: 400/200 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    The Rascal Triangle definition is similar to that of 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:

    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 bellow ):

    R ( n+1 , m+1 ) = ( R ( n , m ) * R ( n , m+1 ) + 1 ) / R ( n-1 , m )

    1
    1   1
     1   2   1
     1   3   3   1
     1   4   5   4   1

    Write a program which computes R( n, m ) the m-th element of the n-th row of the Rascal Triangle.

    输入

    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 singel line of input consisting of 3 space separated decimal integers. The first integer is data set number, N. The secend 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 ≤ mn ≤ 50000 ).

    输出

    Description

    The Rascal Triangle definition is similar to that of 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:

    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 bellow ):

    R ( n+1 , m+1 ) = ( R ( n , m ) * R ( n , m+1 ) + 1 ) / R ( n-1 , m )

    1
    1   1
     1   2   1
     1   3   3   1
     1   4   5   4   1

    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, ( 1 ≤ P ≤ 1000 ), which is the number of data sets that follow. Each data set is a singel line of input consisting of 3 space separated decimal integers. The first integer is data set number, N. The secend 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 ≤ mn ≤ 50000 ).

    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 the Rascal Trianble entry R( n, m ) accurate to the nearest integer value.

    Sample Input

    5
    1 4 0
    2 4 2
    3 45678 12345
    4 12345 9876
    5 34567 11398

    Sample Output

    1 1
    2 5
    3 411495886
    4 24383845
    5 264080263

    Source

    样例输入

    5
    1 4 0
    2 4 2
    3 45678 12345
    4 12345 9876
    5 34567 11398

    样例输出

    1 1
    2 5
    3 411495886
    4 24383845
    5 264080263

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部