推公式得出斐波那契数列
#include<stdio.h> __int64 dp[60]; int main(){ int n; #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int a,b,T; scanf("%d",&T); while(T--){ scanf("%d%d",&a,&b); if(a>b){ printf("0\n"); continue; } dp[a]=1; dp[a-1]=0; for(int i=a+1;i<=b;i++) dp[i]=dp[i-1]+dp[i-2]; printf("%I64d\n",dp[b]); } return 0; }
超级楼梯一样的:
#include<stdio.h> __int64 dp[60]; int main(){ int n; #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int a,b,T; scanf("%d",&T); while(T--){ scanf("%d",&b); a=1; dp[a]=1; dp[a-1]=0; for(int i=a+1;i<=b;i++) dp[i]=dp[i-1]+dp[i-2]; printf("%I64d\n",dp[b]); } return 0; }
时间: 2024-12-27 09:06:21