Subset sequence

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4123    Accepted Submission(s):
2019

Problem Description
Consider the aggregate An= { 1, 2, …, n }. For example,
A1={1}, A3={1,2,3}. A subset sequence is defined as a array of a non-empty
subset. Sort all the subset sequece of An in lexicography order. Your task is to
find the m-th one.
 
Input
The input contains several test cases. Each test case
consists of two numbers n and m ( 0< n<= 20, 0< m<= the total number
of the subset sequence of An ).
 
Output
For each test case, you should output the m-th subset
sequence of An in one line.
 
Sample Input
1 1
2 1
2 2
2 3
2 4
3 10
 
Sample Output
1
1
1 2
2
2 1
2 3 1
 
Author
LL
 
Source
 
Recommend
linle   |   We have carefully selected several similar
problems for you:  2059 2065 2056 2058 2061 

学习网址:http://blog.csdn.net/lianqi15571/article/details/8877014

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
long long c[]={};//c[n]表示长度为n,第一位固定,剩下数字排列形成数列的个数
//易知c[n]=(n-1)*c[n-1]+1
//含义:比如第一位是A1 剩下A2A3。。An 共n-1个数可以固定在第二位,再加上一个空集
bool s[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,i,j;
long long m;
for(i=;i<;i++){
c[i]=(i-)*c[i-]+;
//cout<<c[i]<<endl;
}
long long t,count;
while(scanf("%d %lld",&n,&m)!=EOF){
memset(s,false,sizeof(s));
j=n;
queue<int> q;
while(m){
count=;
t=m/c[j]-(m%c[j]==?:);
m-=t*c[j];
m--;//去掉一个空集!!
j--;
for(i=;i<=n;i++){
if(!s[i]){
count++;
if(count==t+){
break;
}
}
}
s[i]=true;
q.push(i);
}
printf("%d",q.front());
q.pop();
while(!q.empty()){
printf(" %d",q.front());
q.pop();
}
printf("\n");
}
return ;
}

hduoj 2062Subset sequence的更多相关文章

  1. HDUOJ Number Sequence 题目1005

     /*Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  3. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  4. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  5. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  6. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  7. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  8. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  9. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

随机推荐

  1. SVM浅析

    系列博客机器学习总结,主要参考书目<统计学习方法>--李航,涉及数学公式较多,以图片的形式表现.SVM是经典的线性分类方法,通过线性映射投射到希尔伯特空间(完备的赋范内积空间)得到了无穷维 ...

  2. javascript jquery插入元素后事件会被注销

      js jquery插入元素后事件会被注销 document.body.innerHTML += <div id="dd">test</div>  //这 ...

  3. Paste JSON as Code • quicktype 软件的使用

    1.软件图标认知 该软件为json字符串与对象之间相互转户的自动化软件. 下载地址 2.打开软件 配置基本设置 3.生成.h文件 选择生成.h文件 拷贝代码到你管理该对象json文件的.h文件下 4. ...

  4. 安装SSH,配置SSH无密码登陆

    环境:ubuntu16.04 Ubuntu 默认已安装了 SSH client,所以我们还需要安装 SSH server: sudo apt-get install openssh-server 安装 ...

  5. dmp文件恢复oracle数据库

    –创建用户 create user anhui identified by anhui -给予用户权限 grant create session to anhuigrant connect,resou ...

  6. [SDOI2009]HH的项链 树状数组 BZOJ 1878

    题目背景 无 题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断地收集新的贝壳,因此,他的项链 ...

  7. Qt 学习之路 2(22):事件总结

    Qt 学习之路 2(22):事件总结 豆子 2012年10月16日 Qt 学习之路 2 47条评论 Qt 的事件是整个 Qt 框架的核心机制之一,也比较复杂.说它复杂,更多是因为它涉及到的函数众多,而 ...

  8. Redis学习笔记(3)—— 五种数据类型&keys的通用操作

    一.Redis数据结构介绍 redis是一种高级的key-value的存储系统,其中的key是字符串类型,尽可能满足如下几点: 1)key不要太长,最好不要操作1024个字节,这不仅会消耗内存还会降低 ...

  9. mysql 配置utf8 编码,支持 emoji 方法!!!

    utf8_general_ci 已经 过时了...请以后用mysql 考虑使用 utf8mb4, utf8mb4_unicode_ci!!! 兼容性更好. mysql的utf8编码的一个字符最多3个字 ...

  10. photoshop中魔棒工具的使用

    魔术棒工具一般用于纯色背景快速扣图,打开魔术棒工具,设定容差,点击选定背景,清除,文件-保存为png格式图片.ok! 魔棒工具是photoshop中提供的一种比较快捷的抠图工具,对于一些分界线比较明显 ...