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.

27 lines
601 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}