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. Axure RP7.0移动互联网产品原型设计 中文pdf扫描版

    移动互联网原型设计,简单来说,就是使用建模软件制作基于手机或者平板电脑的App,HTML 5网站的高保真原型.在7.0 之前的版本中,使用Axure RP进行移动互联网的建模也是可以的.比如,对于桌面 ...

  2. iOS开发时间处理工具

    1.获取当前的时间 /** 获取当前的时间 */ +(NSString*)getCurrentTimes{ NSDateFormatter *formatter = [[NSDateFormatter ...

  3. 不准使用xib自定义控制器view的大小

    1.AppDelegate.m // // 文 件 名:AppDelegate.m // // 版权所有:Copyright © 2018年 leLight. All rights reserved. ...

  4. redis安装及快速开始

    Redis 简介 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis 与其他 key - value 缓存产品有以下三个特点: Redis支持数据的持久 ...

  5. CI框架源码学习笔记2——Common.php

    上一节我们最后说到了CodeIgniter.php,可是这一节的标题是Common.php,有的朋友可能会觉得很奇怪.事实上,CodeIgniter.php其实包含了ci框架启动的整个流程. 里面引入 ...

  6. UVA10173 Smallest Bounding Rectangle 最小面积矩形覆盖

    \(\color{#0066ff}{题目描述}\) 给定n(>0)二维点的笛卡尔坐标,编写一个程序,计算其最小边界矩形的面积(包含所有给定点的最小矩形). 输入文件可以包含多个测试样例.每个测试 ...

  7. Boost lockfree deque 生产者与消费者多对多线程应用

    boost库中有一个boost::lockfree::queue类型的 队列,对于一般的需要队列的程序,其效率都算不错的了,下面使用一个用例来说明. 程序是一个典型的生产者与消费者的关系,都可以使用多 ...

  8. ExtJS 4.2.1学习笔记(二)——主题theme

    1                 UI组件基础 学习ExtJs就是学习组件的使用.ExtJs4对框架进行了重构,其中最重要的就是形成了一个结构及层次分明的组件体系,由这些组件形成了Ext的控件. E ...

  9. poj3321(dfs序+树状数组)

    题目链接:https://vjudge.net/problem/POJ-3321 题意:给一个普通树(不是二叉树),并且已经编号,每个结点为1或0,有两种操作,对单个结点修改和查询一个结点的子树的所有 ...

  10. Python导入命令 import from

    一 module通常模块为一个文件,直接使用import来导入就好了.可以作为module的文件类型有".py".".pyo".".pyc" ...