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

  1. 3 2

样例输出1

  1. 1 3 2

限制

各个测试点1s

来源

lk

  1. #include <cstdio>
  2.  
  3. #define LL long long
  4. bool use[];
  5. LL jc[];
  6. int n,m;
  7.  
  8. int AC()
  9. {
  10. scanf("%d%d",&n,&m); m--; jc[]=;
  11. for(int i=; i<=n; ++i) jc[i]=(LL)jc[i-]*i;
  12. for(int j,i=; i<=n; ++i)
  13. {
  14. LL tmp=(LL)m/jc[n-i];
  15. m%=jc[n-i];
  16. for(j=; j<=n; ++j)
  17. if(!use[j])
  18. {
  19. if(!tmp) break;
  20. tmp--;
  21. }
  22. use[j]=;
  23. printf("%d ",j);
  24. }
  25. return ;
  26. }
  27.  
  28. int Aptal=AC();
  29. 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. Constructing Roads In JGShining's Kingdom(LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1025 题意:富人路与穷人路都分别有从1到n的n个点,现在要在富人点与穷人点之间修路,但是要求路不能交叉,问最多能 ...

  2. oracle 创建命令

    环境变量设置(在Sqlplus中执行) create or replace directory filepath as 'D:\ORACLEBACKUP'; 备份脚本:expdp system/123 ...

  3. mvc.global.asax事件

    1.global.asax文件概述 global.asax这个文件包含全局应用程序事件的事件处理程序.它响应应用程序级别和会话级别事件的代码. 运行时, Global.asax 将被编译成一个动态生成 ...

  4. swift-自定义TabBar工具栏

    class EBTAppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(ap ...

  5. Android Unresolved Dependencies

    在Android Studio的开发中,在软件中集成了ButterKnife插件,另外需要集成ButterKnife的jar包.因为本地没有现成的,所以在module的build.gradle文件中添 ...

  6. 【备份工具】mydumper

    Mydumper主要特性:是一个针对MySQL的高性能多线程备份和恢复工具,开发人员主要来自MySQL,Facebook,SkySQL公司. 特性: 1:轻量级C语言写的 2:执行速度比mysqldu ...

  7. JavaScript的基本语法(一)

    一.常用的表单元素有: 文本框(text). 密码框(password). 多行文本框(<textarea>) 单选按钮(radio). 复选框(checkbox). 列表框(<se ...

  8. 人工机器:NDC-谷歌机器翻译破世界纪录,仅用Attention模型,无需CNN和RNN

    终于找到ML日报的微信链接,抄之...................................... 请拜访原文链接:[谷歌机器翻译破世界纪录]仅用Attention模型,无需CNN和RNN. ...

  9. Java_Reflect反射

    类是对象,类是java.lang.Class类的实例对象.There is a class named Class class Foo{} public class ClassDemo{ public ...

  10. 函数式编程-将Monad(单子)融入Swift

    前言 近期又开始折腾起Haskell,掉进这个深坑恐怕很难再爬上来了.在不断深入了解Haskell的各种概念以及使用它们去解决实际问题的时候,我会试想着将这些概念移植到Swift中.函数式编程范式的很 ...