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 ...
随机推荐
- @RequestMapping与@ModelAttribute 套路
新接触一个项目,使用了大量注解: 在通过请求路径查看时一直找不到页面的跳转,再查看了文件内所有方法与注解后才找到对应的路径,特此记下: @ModelAttribute("totalfinal ...
- 数据加密实战之记住密码、自动登录和加密保存数据运用DES和MD5混合使用
MD5的简介:MD5即Message-Digest Algorithm 5(信息-摘要算法5),用于确保信息传输完整一致.是计算机广泛使用的杂凑算法之一(又译摘要算法.哈希算法),主流编程语言普遍已有 ...
- Kafka学习文档
本教程假定您是一只小白,没有Kafka 或ZooKeeper 方面的经验. Kafka脚本在Unix和Windows平台有所不同,在Windows平台,请使用 bin\windows\ 而不是bin/ ...
- VS报错:DEBUG Assertion Failed!
使用vs2010时,遇到如下错误 然后点击继续后: 点击终止: 观察变量: 根据提示发现,有可能是断点问题,于是猜想可能是指针的错误. google发现,这种错误可能是由于指针的释放跨越了模块.比如我 ...
- jmeter - 录制web网页
1. 打开JMeter工具 创建一个线程组(右键点击“测试计划”--->“添加”---->“线程组”) 创建一个http代理服务器(右键点击“工作台”--->“添加”-- ...
- 2、OpenCV Python 图像属性获取
__author__ = "WSX" import cv2 as cv import numpy as np image = cv.imread("1.JPG" ...
- Necklace of Beads POJ - 1286
\(\color{#0066ff}{ 题目描述 }\) 一个圈上有n个珠子,有三种颜色可以染,问本质不同的方案数(通过旋转和翻转重合的算一种) \(\color{#0066ff}{输入格式}\) 多组 ...
- P4213 【模板】杜教筛(Sum) min_25筛
\(\color{#0066ff}{ 题目描述 }\) 给定一个正整数\(N(N\le2^{31}-1)\) 求 \(ans_1=\sum_{i=1}^n\varphi(i)\) \(ans_2=\s ...
- LCA【洛谷P2971】 [USACO10HOL]牛的政治Cow Politics
P2971 [USACO10HOL]牛的政治Cow Politics 农夫约翰的奶牛住在N (2 <= N <= 200,000)片不同的草地上,标号为1到N.恰好有N-1条单位长度的双向 ...
- C++基础学习6:内联函数
C++语言新增关键字 inline,用于将一个函数声明为内联函数.在程序编译时,编译器会将内联函数调用处用函数体替换,这一点类似于C语言中的宏扩展. 采用内联函数可以有效避免函数调用的开销,程序执行效 ...