有一长度为N(1<=N<=10)的地板,给定两种不同瓷砖:一种长度为1,另一种长度为2,数目不限。要将这个长度为N的地板铺满,一共有多少种不同的铺法?
#include <iostream>
using namespace std;int cnt = 0; void dfs(int n) {if(n==1) {cnt++;return ;}if(n==2) {cnt++;dfs(n - 1);return ;}dfs(n-1);dfs(n-2);}int main() {int n;cin>>n;dfs(n);cout<<cnt;return 0;}新闻热点
疑难解答