1个测试点TLE,求给看看!
#include <bits/stdc++.h>
using namespace std;
#define endl '\n';
int v[20];
bool b[20];
int Pas_tri[20][20];
int p, n;
bool is = true;
void dfs(int t, int s) {
if (s > p) {
return;
}
if (t > n) {
if (s == p && is) {
for (int i = 1; i <= n; ++i) {
cout << v[i] << " " ;
}
is = false;
}
return;
}
for (int i = 1; i <= n; ++i) {
if (!b[i]) {
b[i] = true;
v[t] = i;
dfs(t + 1, s + i * Pas_tri[n][t]);
b[i] = false;
}
}
}
void best_coder() {
cin >> n >> p;
Pas_tri[1][1] = 1;
for (int i = 2; i <= n; ++i){
for (int j = 1; j <= i; ++j) {
Pas_tri[i][j] = Pas_tri[i - 1][j] + Pas_tri[i - 1][j - 1];
}
}
dfs(1,0);
}
void happy_coder() {
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
best_coder();
return 0;
}