fjnu 1189 Recurrence Relations
来源:互联网 发布:java音乐网站源码 编辑:程序博客网 时间:2024/05/28 22:12
Description
Recurrence relations are where a function is defined in terms of itself and maybe other functions as well. in this problem, we have two functions of interest:
F (N) = F (N - 1) + G (N - 1) ; F (1) = 1
G (N) = G (N - 1) + G (N - 3) ; G (1) = 1, G (2) = 0, G (3) = 1
For a given value of N, compute F (N).
Input
Each line of input will have exactly one integer, 57 > = N > 0.
Output
For each line of input, output F(N).
Sample Input
1457
Sample Output
132035586497
Source:
#include<iostream>
using namespace std;
unsigned F[60]=...{0,1};
unsigned G[60]=...{0,1,0,1};
void list()
...{
int i;
for(i=4;i<=57;i++)
G[i]=G[i-1]+G[i-3];
for(i=2;i<=57;i++)
F[i]=F[i-1]+G[i-1];
}
int main()
...{
list();
int n;
while(cin>>n)
...{
cout<<F[n]<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
unsigned F[60]=...{0,1};
unsigned G[60]=...{0,1,0,1};
void list()
...{
int i;
for(i=4;i<=57;i++)
G[i]=G[i-1]+G[i-3];
for(i=2;i<=57;i++)
F[i]=F[i-1]+G[i-1];
}
int main()
...{
list();
int n;
while(cin>>n)
...{
cout<<F[n]<<endl;
}
return 0;
}
KEY: 不能使用递归的方法,会TLE的,所以采用数组来算,后面的只要出数组拿值;
- fjnu 1189 Recurrence Relations
- Recurrence Relations
- Rabbits and Recurrence Relations
- Relations
- FJNU
- Bad Recurrence
- Resolving Recurrence
- Solve recurrence
- Recurrence UVA10870
- DataSet.Relations
- relations rose
- Box Relations
- HDU3231Box Relations
- JPA relations
- WinCE中recurrence 设置流程
- FJNU字符串
- FJNU字符串
- fjnu 1772
- vdsp4.5(bf561)中的CPLB
- fjnu 1422 赋值问题
- strlen函数与多字节编码的字符串字节长度
- fjnu 1827 Palindrom Numbers
- fjnu 1900 DNA Sorting
- fjnu 1189 Recurrence Relations
- 关于默认构造函数的几个错误认识
- lcc 源码读书笔记之c语言的语义检测
- Visual Basic 基础要点
- fjnu 1655 Crazy tea party
- fjnu 1604 The Hardest Problem Ever
- Microsoft Visual Studio Team System 2008 初步印象
- fjnu 1269 Fuzzy Time
- fjnu 1235 Palindromes