许诺 • 1天前
#include <iostream>
#include <vector>
using namespace std;
int count = 0;
void generate_partitions(int remaining, vector& current) {
if (remaining == 0) {
bool is_palindrome = true;
int n = current.size();
for (int i = 0; i < n / 2; ++i) {
if (current[i] != current[n - 1 - i]) {
is_palindrome = false;
break;
}
}
if (is_palindrome) {
count++;
}
return;
}
for (int i = 1; i <= remaining; ++i) {
current.push_back(i);
generate_partitions(remaining - i, current);
current.pop_back();
}
}
int main() {
int K;
cin >> K;
vector<int> current;
generate_partitions(K, current);
cout << count-1 << endl;
return 0;
}
评论:
请先登录,才能进行评论