BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #35711同步于 2010/2/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

[求助]Fibonacci Again and ...

Rvtea
2010/2/6镜像同步4 回复
Another kind of Fibonacci Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0 Accepted Submission(s): 0 Problem Description As we all known , the Fibonacci series : F(0) = 1, F(1) = 1, F(N) = F(N - 1) + F(N - 2) (N >= 2).Now we define another kind of Fibonacci : A(0) = 1 , A(1) = 1 , A(N) = X * A(N - 1) + Y * A(N - 2) (N >= 2).And we want to Calculate S(N) , S(N) = A(0)2 +A(1)2+……+A(n)2. Input There are several test cases. Each test case will contain three integers , N, X , Y . N : 2<= N <= 231 – 1 X : 2<= X <= 231– 1 Y : 2<= Y <= 231 – 1 Output For each test case , output the answer of S(n).If the answer is too big , divide it by 10007 and give me the reminder. Sample Input 2 1 1 3 2 3 Sample Output 6 196 代码见下~
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
Rvtea机器人#1 · 2010/2/6
#include <stdio.h> void main() { long x,y,a0=1,a1=1,sum,n,p=2; while(scanf("%ld%ld%ld",&n,&x,&y)==3) { if(n>=2&&x>=2&&y>=2) { n--; while(n) { sum=x*a1+y*a0; p+=sum*sum; a0=a1; a1=sum; n--; } } printf("%ld\n",p%10007); a0=1; a1=1; sum=0; p=2; } } 显示的是“time limited exceeded”~这是什么原因?
wks机器人#2 · 2010/2/6
肯定不是这么朴素的算法阿。 试试矩阵法行不行
Rvtea机器人#3 · 2010/2/6
【 在 wks 的大作中提到: 】 : 肯定不是这么朴素的算法阿。 : 试试矩阵法行不行 可以详细地说一点吗?
wks机器人#4 · 2010/2/6
不好说,反正就是用矩阵。 baidu一下“矩阵法,斐波那契”试试。