https://vijos.org/p/1092

描述

输入两个自然数m,n 1<=n<=20,1<=m<=n!
输出n个数的第m种全排列。

如 :
输入 3 1
输出 1 2 3

格式

输入格式

在一行中输入n m

输出格式

一个数列,既n个数的第m种排列
每两个数之间空1格

样例1

样例输入1

3 2

样例输出1

1 3 2

限制

各个测试点1s

来源

lk

 #include <cstdio>

 #define LL long long
bool use[];
LL jc[];
int n,m; int AC()
{
scanf("%d%d",&n,&m); m--; jc[]=;
for(int i=; i<=n; ++i) jc[i]=(LL)jc[i-]*i;
for(int j,i=; i<=n; ++i)
{
LL tmp=(LL)m/jc[n-i];
m%=jc[n-i];
for(j=; j<=n; ++j)
if(!use[j])
{
if(!tmp) break;
tmp--;
}
use[j]=;
printf("%d ",j);
}
return ;
} int Aptal=AC();
int main(){;}

Vijos——T 1092 全排列的更多相关文章

  1. Vijos 1092 全排列

    题目链接 来个水题..难得的1Y. #include <cstdio> #include <cstring> #include <iostream> using n ...

  2. vijosP1092 全排列

    vijosP1092 全排列 链接:https://vijos.org/p/1092 [思路] 数学+搜索. 根据序号依次确定每一个数. 首先我们可以把未选的数看作一个可选择集合,其次把寻找过程看作一 ...

  3. PHP实现全排列(递归算法)

    算法描述:如果用P表示n个元素的全排列,而Pi表示n个元素中不包含元素i的全排列,(i)Pi表示在排列Pi前面加上前缀i的排列,那么n个元素的全排列可递归定义为:    ① 如果n=1,则排列P只有一 ...

  4. hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)

    xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串.                      (题于文末) 知识点: n个元素,其中a1,a2,··· ...

  5. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  6. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  7. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  8. [LeetCode] Permutations 全排列

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  9. 【BZOJ 1061】【Vijos 1825】【NOI 2008】志愿者招募

    http://www.lydsy.com/JudgeOnline/problem.php?id=1061 https://vijos.org/p/1825 直接上姜爷论文... #include< ...

随机推荐

  1. Android内存解析(一)—从Linux系统内存逐步认识Android应用内存

    总述 Android应用程序被限制了内存使用上限,一般为16M或24M(具体看系统设置),当应用的使用内存超过这个上限时,就会被系统认为内存泄漏,被kill掉.所以在android开发时,管理好内存的 ...

  2. Android+Jquery Mobile学习系列(3)-创建Android项目

    前两章分别对开发环境和Jquery Mobile基础知识进行了介绍,本章介绍创建一个Android项目,并使用WebView控件显示HTML数据. 首先创建一个Android Application项 ...

  3. Python 网络爬虫与信息获取(二)—— 页面内容提取

    1. 获取超链接 python获取指定网页上所有超链接的方法 links = re.findall(b'"((http|ftp)s?://.*?)"', html) links = ...

  4. JS代码放在哪里比较好!

    在页面上加上<script></script>只有2个地方:head中,body体中 如果外部的JS文件,在head中加,写页面特效js放在body后面. <html&g ...

  5. 【K8s】Kubernetes架构理解

    抽空学习了一下Kubernetes,感觉和大数据领域内集群的资源管理.任务调度等有异曲同工之处,简单总结一下备忘. [概念] Kubernetes是一个工业级的容器编排平台,单词有点长,常用K8s代称 ...

  6. LeetCode刷题 1. Two Sum 两数之和 详解 C++语言实现 java语言实现

    1. Two Sum 两数之和 Given an array of integers, return indices of the two numbers such that they add up ...

  7. 一个能让cin和scanf 一样快的方法:

    cin慢是有原因的,其实默认的时候,cin与stdin总是保持同步的,也就是说这两种方法可以混用,而不必担心文件指针混乱,同时cout和stdout也一样,两者混用不会输出顺序错乱.正因为这个兼容性的 ...

  8. EasyUI 编写实体类树状选择器

    <%@ page contentType="text/html;charset=UTF-8"%> <%@ include file="/WEB-INF/ ...

  9. Project Management -- How to use GitHub with Git

    如何通过Git使用GitHub ——PM曾子轩 从未使用过Git 一.从官网下载Git 此部分略 二.用Git连接上GitHub(为保持完整性,此部分引用博客:https://www.cnblogs. ...

  10. 关于angular双向绑定的一个问题,百度无果,还请帮忙解惑。

    用了一段时间anjular蛮好用的.其实用的功能不多.主要用于列表数据绑定以及一些简单效果的绑定,但是最近出现一个现象,百度无果,居然没有人遇到.现在描述一下,截图不方便,希望有人解惑. 列表ng-r ...