cpp
#include<iostream>
#include<stdio.h>
using namespace std;
int f(int n)
{
if (n == 1)return 1;
if (n == 2)return 1;
return f(n - 1) + f(n - 2);
}
int main()
{
int n;
cin >> n;
cout << f(n) << endl;
return 0;
}
cpp
#include<iostream>
#include<stdio.h>
using namespace std;
int n;
int arr[16];
void dfs(int u)
{
if (u > n)
{
for (int i = 1;i <= n;i++)
{
if (arr[i] == 1)
{
cout << i << " ";
}
}
cout << endl;
return;
}
arr[u] = 2;
dfs(u + 1);
arr[u] = 1;
dfs(u + 1);
}
int main()
{
cin >> n;
dfs(1);
return 0;
}
cpp
#include<iostream>
using namespace std;
#include<vector>
int n;
int arr[10];
int arr2[10];//1没用过,2用过
vector<int>v;
void dfs(int u)
{
if (u > n)
{
for (int i = 1;i <= n;i++)
{
cout << arr[i]<<" ";
}
cout << endl;
}
for (int i = 1;i <= n;i++)
{
if (arr2[i] == 1)
{
arr[u] = i;
arr2[i] = 2;
dfs(u + 1);
arr2[i] = 1;
}
}
}
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
{
arr2[i] = 1;
}
dfs(1);
return 0;
}
cpp
#include<iostream>
using namespace std;
int arr[26];
int use[26];//1没用过,2用过
int n, k;
void dfs(int u)
{
if (u > k)
{
for (int i = 1;i <= k;i++)
{
cout << arr[i] << " ";
}
cout << endl;
return;
}
for (int i = 1;i <= n;i++)
{
if (use[i] == 1 && i > arr[u - 1])
{
arr[u] = i;
use[i] = 2;
dfs(u + 1);
use[i] = 1;
}
}
}
int main()
{
cin >> n >> k;
for (int i = 1;i <= n;i++)
{
use[i] = 1;
}
dfs(1);
return 0;
}
cpp
#include<iostream>
using namespace std;
long long dfs(int n)
{
if(n==1)return 1;
return n*dfs(n-1);
}
int main()
{
int n;
cin>>n;
cout<<dfs(n)<<endl;
return 0;
}
cpp
#include<iostream>
using namespace std;
#include<algorithm>
int arr[10];
int arr2[10];
int test[10];
bool use[10];
int n;
void dfs(int u)
{
if (u > n)
{
/* int flag = 1;
for (int i = 1;i <= n;i++)
{
if (arr2[i] != test[i])
{
flag = 0;
}
test[i] = arr2[i];
}
if (flag == 0)
{*/
for (int j = 1;j <= n;j++)
{
cout << arr2[j] << " ";
}
cout << endl;
//}
return;
}
for (int i = 1;i <= n;i++)
{
if (!use[i])
{
arr2[u] = arr[i];
use[i] = true;
dfs(u + 1);
use[i] = false;
while (i + 1 <= n && arr[i + 1] == arr[i]) i++;
}
}
}
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> arr[i];
}
sort(arr+1, arr + n+1);
/*for (int i = 1;i <= n;i++)
{
cout << arr[i];
}*/
dfs(1);
return 0;
}