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. C# WINFORM 局域网PING 工具(技术改变世界-cnblog)

    WINFORM 局域网PING 工具(技术改变世界-cnblog) 需求: 1.实时更新 日期时间 2.可以ping多个IP 地址,必须判断 IP地址的正确性,不能为广播地址 3.对ping结果的显示 ...

  2. ASP.NET通用权限系统快速开发框架

    系统在线演示地址: http://120.90.2.126:8051 登录账户:system,密码:system### DEMO下载地址: http://download.csdn.net/detai ...

  3. 【POJ 2442】 Sequence

    [题目链接] http://poj.org/problem?id=2442 [算法] 堆 [代码] #include <algorithm> #include <bitset> ...

  4. Coursera Algorithms week1 查并集 练习测验:2 Union-find with specific canonical element

    题目原文: Add a method find() to the union-find data type so that find(i) returns the largest element in ...

  5. C# 取两位小数

    double s=0.55555;result=s.ToString("#0.00");//点后面几个0就保留几位 如果要四舍五入的话,用这个double dbdata = 0.5 ...

  6. B - Alyona and mex(构造)

    Problem description Alyona's mother wants to present an array of n non-negative integers to Alyona. ...

  7. rabbitmq镜像模式初体验

    rabbitmq-01: yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm wget ...

  8. ES6 学习小结1

    ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015. 也就是说,ES6就是ES2015. ...

  9. informix 通过ADO或ODBC连接提取数据时出现中文乱码的解决方法

    最近在做一个项目,是对INFORMIX数据库的数据进行大数据分析,INFORMIX数据库数据有上亿条,没有linux的Root权限和informix数据的生产权限,只能读取.客户要求结果显示在内网wi ...

  10. IE浏览器发展史