Vijos——T 1092 全排列
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 全排列的更多相关文章
- Vijos 1092 全排列
题目链接 来个水题..难得的1Y. #include <cstdio> #include <cstring> #include <iostream> using n ...
- vijosP1092 全排列
vijosP1092 全排列 链接:https://vijos.org/p/1092 [思路] 数学+搜索. 根据序号依次确定每一个数. 首先我们可以把未选的数看作一个可选择集合,其次把寻找过程看作一 ...
- PHP实现全排列(递归算法)
算法描述:如果用P表示n个元素的全排列,而Pi表示n个元素中不包含元素i的全排列,(i)Pi表示在排列Pi前面加上前缀i的排列,那么n个元素的全排列可递归定义为: ① 如果n=1,则排列P只有一 ...
- hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)
xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串. (题于文末) 知识点: n个元素,其中a1,a2,··· ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations 全排列
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- 【BZOJ 1061】【Vijos 1825】【NOI 2008】志愿者招募
http://www.lydsy.com/JudgeOnline/problem.php?id=1061 https://vijos.org/p/1825 直接上姜爷论文... #include< ...
随机推荐
- POJ 2728(最优比率生成树+01规划)
Dese ...
- expectation-maximization algorithm ---- PRML读书笔记
An elegant and powerful method for finding maximum likelihood solutions for models with latent varia ...
- Mysql数据库系列
详情点击 MySQL基础 Mysql表操作 Mysql插入 更新 删除 查询操作 Mysql创建用户和授权 基本的Mysql语句 Mysql库的操作 Mysql表的操作 Mysql数据类型(一) My ...
- Struts/Hibernate/Spring源码下载
Struts: https://olex.openlogic.com/packages/struts Hibernate: https://olex.openlogic.com/packages/hi ...
- java线程中断
public void Thread.interrupt() // 无返回值 public boolean Thread.isInterrupted() // 有返回值 public static b ...
- Android 判断app是否安装
1. private boolean isAppInstalled(Context context, String uri) { PackageManager pm = context.getPack ...
- page事件
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- sql server 还原数据库,数据库提示正在还原中的处理办法
还原数据库时,提示还原成功,可是数据库列表中该数据库显示正在还原中: 执行此命令即可: RESTORE DATABASE EnterPriseBuilding WITH RECOVERY 了解SQ ...
- MAMP PRO mysql无法启动
mac上可能勾选了软件自动更新,然后MAMP PRO 升级了. 升级了之后,mysql启动就出问题了,看报错日志: InnoDB: The error means the system cannot ...
- MySQL在Linux下的表名如何不区分大小写
MySQL在Linux下的表名如何不区分大小写 今天测试的时候,遇到一些问题,明明看到数据,就是查不出来;后来发现,在linux下, mysql的表名区分大小写,而在windows下是不区分,从w ...