The Rascal Triangle
2013-07-24 21:48
183 查看
Description
![](https://icpcarchive.ecs.baylor.edu/components/com_onlinejudge/images/button_pdf.png)
The Rascal Triangle definition is similar to that of the Pascal Triangle. The rows are numbered from the top starting with 0. Each rown contains n +
1 numbers indexed from 0 to n. Using R(n, m) to indicate the index m item in the index n row:
[align=center]R(n, m) = 0 for n < 0 OR m < 0 OR m > n[/align]
The first and last numbers in each row (which are the same in the top row) are 1:
[align=center]R(n, 0) = R(n, n) = 1[/align]
The interior values are determined by (UpLeftEntry*UpRightEntry + 1)/UpEntry (see the parallelogram in the array below):
[align=center]R(n + 1, m + 1) = (R(n, m)*R(n, m + 1) + 1)/R(n - 1, m)[/align]
![](https://icpcarchive.ecs.baylor.edu/external/58/p5801.png)
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
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
P
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
1000),
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 ( 0
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
m
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
n
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
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 theRascal Triangle entry R(n, m) accurate
to the nearest integer value.
Sample Input
Sample Output
这到题我首先的感觉就想到递归,但再到时间问题和数据太大!这用递归是不能完成这庞大的数据的!!经过苦思冥想,想到退出
公式,即通项!具体通项在代码中:
![](https://icpcarchive.ecs.baylor.edu/components/com_onlinejudge/images/button_pdf.png)
The Rascal Triangle definition is similar to that of the Pascal Triangle. The rows are numbered from the top starting with 0. Each rown contains n +
1 numbers indexed from 0 to n. Using R(n, m) to indicate the index m item in the index n row:
[align=center]R(n, m) = 0 for n < 0 OR m < 0 OR m > n[/align]
The first and last numbers in each row (which are the same in the top row) are 1:
[align=center]R(n, 0) = R(n, n) = 1[/align]
The interior values are determined by (UpLeftEntry*UpRightEntry + 1)/UpEntry (see the parallelogram in the array below):
[align=center]R(n + 1, m + 1) = (R(n, m)*R(n, m + 1) + 1)/R(n - 1, m)[/align]
![](https://icpcarchive.ecs.baylor.edu/external/58/p5801.png)
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
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
P
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
1000),
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 ( 0
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
m
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
n
![](https://icpcarchive.ecs.baylor.edu/external/58/5801img2.png)
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 theRascal Triangle 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
这到题我首先的感觉就想到递归,但再到时间问题和数据太大!这用递归是不能完成这庞大的数据的!!经过苦思冥想,想到退出
公式,即通项!具体通项在代码中:
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <vector> #include <queue> #include <cstdio> #include <cmath> #include <string> #include <stack> #include <cctype> using namespace std; int main() { int t,n; long long x,y; scanf("%d",&t); while(t--) { scanf("%d%lld%lld",&n,&x,&y); if(x == 0 || x == y || y == 0) { printf("%d 1\n",n); continue; } printf("%d %lld\n",n,(x-y)*y+1); } return 0; }
相关文章推荐
- HDU4237 The Rascal Triangle
- HDU_4237_The Rascal Triangle(推公式)
- HDU4237:The Rascal Triangle
- The Rascal Triangle 题解
- hdu4237 The Rascal Triangle 规律题
- Given an N layers triangle in mathematic like the graph below
- poj 1163 The Triangle
- The Triangle
- POJ 1069 The Bermuda Triangle
- The Triangle POJ - 1163
- POJ1085 The Triangle War: 记忆化搜索
- poj 1163 The Triangle 因为这个,发现DP很有意思
- [Codeforces Round #195 (Div. 2)] A. Vasily the Bear and Triangle
- POJ 1163 The Triangle
- POJ The Triangle
- Introduction to Java Programming编程题11.1<The triangle class>
- POJ 1163 The Triangle
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
- Codeforces-336A-Vasily the Bear and Triangle