暴力搜索,用STL力的next_permutation很方便
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#define mst(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int MAXN = 1000001;
int n, sum;
int myints[10];
bool check(){
int temp[10];
for(int i = 0; i < n; i++){
temp[i] = myints[i];
}
for(int i = 0; i < n-1; i++){
for(int j = n-1; j >= i+1; j--){
temp[j] = temp[j-1] + temp[j];
}
}
return temp[n-1] == sum;
}
int main()
{
cin >> n >> sum;
for(int i = 0; i < n; i++){
myints[i] = i+1;
}
do{
if(check()){
for(int i = 0; i < n-1; i++){
cout << myints[i] << " ";
}
cout << myints[n-1] << endl;
return 0;
}
}while(next_permutation(myints, myints+n));
return 0;
}