Files
python/TangDou/DiTui/CaiDai.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

27 lines
601 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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