0
点赞
收藏
分享

微信扫一扫

一只小蜜蜂 HDU2044

巧乐兹_d41f 2022-07-13 阅读 115


一只小蜜蜂 HDU2044

一只小蜜蜂 HDU2044_c++

每一步都可以加1或者加2,那么走到b的时候应该是b-1和b-2加起来,即递推方程是dp[b] = dp[b-1]+dp[b-2]

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
int a,b;
void solve(){
cin>>a>>b;
b -= a ; //第几项
int x = 0,y = 1,z = 1;
for(int i = 1;i <= b;++i)
z = x + y,x = y,y = z;
cout<<z<<"\n";
}
signed main(){
IOS;
int tt;cin>>tt;
while(tt--)
solve();
return 0;
}


举报

相关推荐

0 条评论