You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
// 彩带
|
|
|
|
|
// https://blog.csdn.net/weixin_43736974/article/details/108246801
|
|
|
|
|
// 从已知到未知,找规律
|
|
|
|
|
// 设 f(n)为有n条彩带情况下的方案数,推导
|
|
|
|
|
// f(1)=2 ---->全红或全白
|
|
|
|
|
// f(2)=2 ---->红白或白红
|
|
|
|
|
// f(3)=4 ---->题目中说到的
|
|
|
|
|
// f(4)=6 ---->再多推导一步,根据规则来。
|
|
|
|
|
// ...
|
|
|
|
|
// f(n)=f(n-1)+f(n-2)
|
|
|
|
|
|
|
|
|
|
int dp(int n) {
|
|
|
|
|
if (n == 1) return 2;
|
|
|
|
|
if (n == 2) return 2;
|
|
|
|
|
return dp(n - 1) + dp(n - 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int n = 10;
|
|
|
|
|
cout << dp(n) << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|