hduoj 2062Subset sequence
Subset sequence
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4123 Accepted Submission(s):
2019
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.
consists of two numbers n and m ( 0< n<= 20, 0< m<= the total number
of the subset sequence of An ).
sequence of An in one line.
2 1
2 2
2 3
2 4
3 10
1
1 2
2
2 1
2 3 1
学习网址: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的更多相关文章
- HDUOJ Number Sequence 题目1005
/*Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
随机推荐
- Python如何打包EXE可执行文件
一.安装Pyinstaller 使用Python打包EXE可执行文件时,需要使用Pyinstaller,使用命令pip install PyInstaller进行安装,如下图: 安装成功后的效果如下图 ...
- 一种Web服务的go语言实现
0.引言 go语言已成为当今web后台开发的首选语言,关键在于其简洁性和高效并发特性.go中提供了丰富通用的http开发接口,但一般需要对其进一步封装才能更好的用于实际项目中.因此,本文基于开源库(g ...
- ubuntu - 14.04,安装Go语言(谷歌公司开发的一种语言)
Go语言下载地址:https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz 安装: 1,以root身份在shell里执行: ta ...
- 编译安装log4cxx
1.介绍 Log4cxx是开放源代码项目Apache Logging Service的子项目之一,是Java社区著名的log4j的c++移植版,用于为C++程序提供日志功能,以便开发者对目标程序进行调 ...
- H5教程(二),CSS入门(一)选择器
这是我的第二篇博客,H5教程CSS入门,适合刚开始学习H5的新手,让我们共同进步. 1. CSS简介 1.1 CSS是什么? CSS称为样式层叠表,是用于增强或控制网页样式,并允许将样式信息与网页 ...
- springboot junit单元测试报错
1.测试类中如下方框为主函数 2.application.yml注意如下2个地方 3.主函数
- Django / Python 链接MySQL数据库
https://www.cnblogs.com/wupeiqi/articles/5237704.html python (Django)中使用MySQL 首先python3中没有 MySQLdb 需 ...
- 牛客国庆集训day5 G 贵族用户 (模拟)
链接:https://www.nowcoder.com/acm/contest/205/G来源:牛客网 题目描述 终于活成了自己讨厌的样子. 充钱能让你变得更强. 在暖婊这个游戏里面,如果你充了x元钱 ...
- 谷歌通过ajax获取本地JSON文件,为什么会显示跨域?转载的
在本地写了一段JSON代码,然后用ajax读取后,在浏览器打开,发现谷歌提示涉及到跨域问题, 但是跨域是由于协议,域名,端口中有一个不同,才会跨域,我在本地访问自己的文件,怎么和跨域扯上关系了?? 谷 ...
- Python的安装位置与Python库
如何查看Python的安装位置: 输入 where python ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...