排列型递归应用
#include <bits/stdc++.h>
using namespace std;
int v[10], p[10], n, ans;
int get(int l, int r) {
int num = 0;
for (int i = r; i >= l; --i) num = num * 10 + p[i];
return num;
}
void dfs(int t) {
if (t > 9) {
for (int i = 1; i <= 7; ++i) {
int a = get(1, i);
for (int j = 1; j < 9 - i; ++j) {
int k = get(i + 1, i + j);
int m = get(i + j + 1, 9);
if (k % m == 0 && a + k / m == n) ans++;
}
}
return;
}
for (int i = 1; i <= 9; ++i) {
if (v[i] == 0) {
v[i] = 1, p[t] = i;
dfs(t + 1);
v[i] = 0;
}
}
}
int main() {
cin >> n;
dfs(1);
cout << ans << endl;
return 0;
}