[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 ;
}
[NYIST32]组合数(状压,枚举,暴力)的更多相关文章
- [POJ1681]Painter's Problem(高斯消元,异或方程组,状压枚举)
题目链接:http://poj.org/problem?id=1681 题意:还是翻格子的题,但是这里有可能出现自由变元,这时候枚举一下就行..(其实这题直接状压枚举就行) /* ━━━━━┒ギリギリ ...
- HDU2489【状压枚举】
题意: 给你n个点的图,然后让你在图里挑m个点,达到sumedge/sumnode最小 思路: 由于数据范围小,状压枚举符合m个点的状态,我是用vactor存了结点位置,也记录了结点的sum值,然后跑 ...
- POJ3734【状压枚举】
题意: 给你两个01矩阵,去掉矩阵B的某些行和某些列,问处理后的矩阵B能否变成矩阵A: 思路: 数据较小,状压枚举B矩阵列的数量=A矩阵列的数量时的状态,然后搞定了列,贪心判断B矩阵的行就好了: #i ...
- 排列perm HYSBZ - 1072(状压dp/暴力)
Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能被2整除,其中末位为2的有30种,末位为4的有60种. Input ...
- CF895C Square Subsets (组合数+状压DP+简单数论)
题目大意:给你一个序列,你可以在序列中任选一个子序列,求子序列每一项的积是一个平方数的方案数. 1<=a[i]<=70 因为任何一个大于2的数都可以表示成几个质数的幂的乘积 所以我们预处理 ...
- POJ - 1753 Flip Game(状压枚举)
https://vjudge.net/problem/POJ-1753 题意 4*4的棋盘,翻转其中的一个棋子,会带动邻接的棋子一起动.现要求把所有棋子都翻成同一种颜色,问最少需要几步. 分析 同一个 ...
- POJ 1753 Flip Game(高斯消元+状压枚举)
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45691 Accepted: 19590 Descr ...
- hdu 4770 状压+枚举
/* 长记性了,以后对大数组初始化要注意了!140ms 原来是对vis数组进行每次初始化,每次初始化要200*200的复杂度 一直超时,发现没必要这样,直接标记点就行了,只需要一个15的数组用来标记, ...
- CF1556F Sports Betting (状压枚举子集DP)
F 对于一张比赛图,经过缩点,会得到dag,且它一定是transitive的,因此我们能直接把比赛图缩成一个有向链.链头作为一个强连通分量,里面的所有点都是胜利的 定义F(win)表示win集合作为赢 ...
随机推荐
- 2014_acmicpc_shanghai_google
I http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84975#problem/I 题意:我方有n个士兵,敌方有m个士兵,每个士兵有攻击力和 ...
- JS 数组的基础知识
数组 一.定义 1.数组的文字定义 广义上说,数组是相同类型数据的集合.但是对于强类型语言和弱类型语言来说其特点是不一样的.强类型语言数组和集合有以下特点. 数组强类型语言:1.数组里面只能存放相同数 ...
- iOS Automation Test
google resource for KIF: http://www.oschina.net/translate/ios-ui-testing-with-kif
- C#中String 与Color之间的相互转换
C#中String 与Color之间的相互转换 ————————————宋兴柱 其实,我们平常如果要在数据库存放Color类型值的话,肯定会在数据库中建立varchar类型.对吧.但是Colo ...
- 企业级账号更新app
企业级账号 版本更新总结 参考:http://jingyan.baidu.com/article/a3aad71aa5fbfbb1fb0096b1.html 1.打包ipa,plist工具 ...
- Codeforces Round #247 (Div. 2) C题
赛后想了想,然后就过了.. 赛后....... 我真的很弱啊!想那么多干嘛? 明明知道这题的原型就是求求排列数,这不就是 (F[N]-B[N]+100000007)%100000007: F[N]是1 ...
- LNMP笔记:安装 Xcache 缓存扩展,降低服务器负载
LNMP笔记:安装 Xcache 缓存扩展,降低服务器负载 2014/11/27 教程笔记 4,743 14 WordPress 精品主机推荐:恒创主机 | 阿里云(本站目前所用云主机) 倡萌 ...
- POJ 2075
#include<iostream> #include<stdio.h> #include<string> #include<map> #include ...
- D&F学数据结构系列——B树(B-树和B+树)介绍
B树 定义:一棵B树T是具有如下性质的有根树: 1)每个节点X有以下域: a)n[x],当前存储在X节点中的关键字数, b)n[x]个关键字本身,以非降序存放,因此key1[x]<=key2[x ...
- Good Bye 2015 A. New Year and Days 签到
A. New Year and Days Today is Wednesday, the third day of the week. What's more interesting is tha ...