[NYIST32]组合数(状压,枚举,暴力)

题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=32

求n个数中挑出r个数字的所有情况,最后倒序输出所有情况。

状压枚举所有情况就是了,判断长度是否符合条件。

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(LL i = 0; i < (len); i++)
#define For(i, a, len) for(LL i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Fuint(a) memset((a), 0x7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long Uint;
typedef pair<LL, LL> pii;
typedef pair<string, LL> psi;
typedef map<string, LL> msi;
typedef vector<LL> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ; int a[maxn];
int t[maxn];
int n, r, cnt;
vector<vi> v; int main() {
// FRead();
Rep(i, maxn+) a[i] = i + ;
while(~scanf("%d%d", &n, &r)) {
int nn = << n;
vi p; v.cl();
For(i, , nn) {
cnt = ;
Rep(j, n) {
if(i & ( << j)) t[cnt++] = a[j];
}
if(cnt == r) {
p.cl();
for(int j = cnt - ; j >= ; j--) p.pb(t[j]);
v.pb(p);
}
}
sort(v.begin(), v.end());
for(int i = v.size() - ; i >= ; i--) {
Rep(j, r) {
printf("%d", v[i][j]);
}
printf("\n");
}
}
RT ;
}
上一篇:python中的printf:%号拼接字符串和format函数


下一篇:Continue