[問題] 費氏數列+DP+大數
看板C_and_CPP (C/C++)作者seedpk5079 (fhcrc 99th ooxx)時間16年前 (2009/03/12 22:49)推噓3(3推 0噓 7→)留言10則, 3人參與討論串1/3 (看更多)
http://0rz.tw/NQaec
這是題目網址
看了裡面的討論後
小弟覺得這是費氏數列大數化的樣子
所以又免不了DP
我決定每一項都開一個50個int陣列給她
所以我設定了個自訂型態
但是當我做大數函數時(add)
卻發現無法編譯
以下是程式原碼
#include<stdio.h>
#include<string.h>
int b;
typedef struct big_number{
int ooxx[50];
big_number(){
int ooxx[50]={};
}
};
struct big_number dp[120],oxox[2];/*oxox[0] oxox[1]打算拿來當add的參數用*/
big_number add(big_number oxox[0],big_number oxox[1]){
int total[50]={},i,j,k,h,m;
for(i=0;oxox[0].ooxx[i]!='0';++i){}
for(j=0;oxox[1].ooxx[j]!='0';++i){}
k=((i>=j)?i:j);
for(m=k;m>0;--m){
int l=0;
total[l]=oxox[0].ooxx[m]+oxox[1].ooxx[m]+total[l];
if(total[l]>=10){
total[l+1]=total[l]%10;
total[l]=total[l]/10;
}
l++;
}
if(total[k+1]!=0){
k++;
}
for(h=0;;h++){
oxox[1].ooxx[h]=total[k];
k--;
}
return oxox[1];
}
big_number Fibonacc(int b){
if(b==1||b==2){
dp[1].ooxx[0]=1;
dp[0].ooxx[0]=1;
return dp[1];
}
else if(dp[b].ooxx[0]!=0){
return dp[b];
}
else{
return dp[b]=add(Fibonacc(b-1),Fibonacc(b-2));
}
}
int main(){
int n;
while(scanf("%d",&n)!=EOF ){
int day=0,i=0,number=0;
Fibonacc(n*5);
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.143.159.169
推
03/12 22:55, , 1F
03/12 22:55, 1F
推
03/12 22:59, , 2F
03/12 22:59, 2F
→
03/12 23:15, , 3F
03/12 23:15, 3F
→
03/12 23:16, , 4F
03/12 23:16, 4F
→
03/12 23:16, , 5F
03/12 23:16, 5F
→
03/12 23:17, , 6F
03/12 23:17, 6F
→
03/12 23:17, , 7F
03/12 23:17, 7F
→
03/12 23:18, , 8F
03/12 23:18, 8F
→
03/12 23:18, , 9F
03/12 23:18, 9F
推
03/13 19:42, , 10F
03/13 19:42, 10F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章