其中,蜂房的結構如下所示。
3
這道水題不用DP,用菲波那切數列可以簡單的解決,但是要注意的是,菲波那切數列在40位以后有可能超過32位,所以數組用單純的int型不能正確存儲,得用long long型或
—int64型存儲。
我的代碼:
#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<iomanip>#include<string.h>using namespace std;int main(){ int n, e1, e2; long long r[100];//注意用的是long long型 scanf("%d", &n); while(n--) { int i; cin >> e1 >> e2; if (e1 > e2) swap (e1, e2); e1 = e2 - e1 ; r[0] = 1; r[1] = 1; for (i = 2; i <= 51; i++) r[i] = r[i-1] + r[i-2]; cout << r[e1] << endl; } return 0;}
新聞熱點
疑難解答