文章
68
粉丝
691
获赞
26
访问
578.4k
#define ll long long
#define vec vector<int>
#define inf 0x3f3f3f3f
#define MAX 25
#define P pair<int,int>
#define MOD 1000000
int n, m, vis[MAX];
void pprint(vec v) {
for (int i = 0; i < v.size() - 1; i++)cout << setw(3) << v[i];
cout << setw(3) << v[v.size() - 1] << endl;
}
void zuHe(int cnt, vec ve) {
if (cnt == m) pprint(ve);
for (int i = 1; i <= n; i++) {
if (!vis[i] && (ve.empty() || i > ve[ve.size() - 1])) {
vis[i] = 1;
ve.push_back(i);
zuHe(cnt + 1, ve);
ve.pop_back();
vis[i] = 0;
}
}
}
int main() {
while (cin >> n >> m) {
vec v;
zuHe(0, v);
}
}
登录后发布评论
暂无评论,来抢沙发