309
Объяснение:
F(1) = 1
F(2) = 3
F(n) = F(n – 1) * n + F(n – 2) * (n – 1) при n > 2
Немного посчитаем подставляя значения n и предыдущих F(n)
n = 3 F(1) = 1 F(2) = 3
F(3) = F(3 – 1) * 3 + F(3 – 2) * (3 – 1) = F(2) * 3 + F(1) * 2 = 3 * 3 + 1 * 2 = 9 + 2 = 11
n = 4 F(2) = 3 F(3) = 11
F(4) = F(4 – 1) * 4 + F(4 – 2) * (4 – 1) = F(3) * 4 + F(2) * 3 = 11 * 4 + 3 * 3 = 44 + 9 = 53
n = 5 F(3) = 11 F(4) = 53
F(5) = F(5 – 1) * 5 + F(5 – 2) * (5 – 1) = F(4) * 5 + F(3) * 4 = 53 * 5 + 11 * 4 = 265 + 44 = 309
#include <algorithm>
using namespace std;
void sort(int a[], int n) {
for (int i = 0; i < n; i++) {
int j = i;
while (j > 0 && a[j - 1] > a[j]) {
if (a[j - 1] > a[j]) {
swap(a[j - 1], a[j]);
}
j--;
}
}
}
int main() {
int n;
cin >> n;
int count = 0;
int *a = new int[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, n);
for (int i = 0; i < n; i++) {
if (a[i] != a[i + 1]) {
count++;
}
cout << a[i] << " ";
}
cout << endl << count;
delete[]a;
}
309
Объяснение:
F(1) = 1
F(2) = 3
F(n) = F(n – 1) * n + F(n – 2) * (n – 1) при n > 2
Немного посчитаем подставляя значения n и предыдущих F(n)
n = 3 F(1) = 1 F(2) = 3
F(3) = F(3 – 1) * 3 + F(3 – 2) * (3 – 1) = F(2) * 3 + F(1) * 2 = 3 * 3 + 1 * 2 = 9 + 2 = 11
n = 4 F(2) = 3 F(3) = 11
F(4) = F(4 – 1) * 4 + F(4 – 2) * (4 – 1) = F(3) * 4 + F(2) * 3 = 11 * 4 + 3 * 3 = 44 + 9 = 53
n = 5 F(3) = 11 F(4) = 53
F(5) = F(5 – 1) * 5 + F(5 – 2) * (5 – 1) = F(4) * 5 + F(3) * 4 = 53 * 5 + 11 * 4 = 265 + 44 = 309