Light oj 1060 - nth Permutation(dfs 计数)

python-调用动态链接库dll/so的方法 使用python ctyeps CDLL来调用linux下的so动态链接库或windows下的dll动态链接库 阅读详情

1060 - nth Permutation
Time Limit: 2 second(s)Memory Limit: 32 MB

Given a string of characters, we can permute the individual characters to make new strings. At first we order the string into alphabetical order. Then we start permuting it.

For example the string 'abba' gives rise to the following 6 distinct permutations in alphabetical order.

aabb 1

abab 2

abba 3

baab 4

baba 5

bbaa 6

Given a string, you have to find the nth permutation for that string. For the above case 'aabb' is the 1st and 'baab' is the 4th permutation.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case contains a non empty string of lowercase letters with length no more than 20 and an integer n (0 < n < 231).

Output

For each case, output the case number and the nth permutation. If the nth permutation doesn't exist print 'Impossible'.

Sample Input

Output for Sample Input

3

aabb 1

aabb 6

aabb 7

Case 1: aabb

Case 2: bbaa

Case 3: Impossible

 


PROBLEM SETTER: JANE ALAM JAN




#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define bug printf("hihi\n")

#define eps 1e-8

typedef long long ll;

using namespace std;
#define N 22

long long p[N];

int vis[30];


void inint()
{
    p[0]=1;
    for(int i=1;i<N;i++)
        p[i]=p[i-1]*i;
}

void dfs(int len,ll pos)
{
     if(len==0) return ;
     int i;
     ll temp=p[len-1];
     for(i=0;i<26;i++)
     {
        if(vis[i]==0) continue;
        ll ha=temp;
        for(int j=0;j<26;j++)
        {
            if(j==i) ha/=p[vis[i]-1];
            else ha/=p[vis[j]];
        }

        if(ha<pos) {
             pos-=ha;
             continue;
        }
        printf("%c",i+'a');
        vis[i]--;
        dfs(len-1,pos);
     }
}

int main()
{
     inint();
     int i,j,t,ca=0;
     long long pos;
     scanf("%d",&t);

     char c[N];

     while(t--)
     {
         scanf("%s%lld",c,&pos);

         memset(vis,0,sizeof(vis));
         int len=strlen(c);

         for(int i=0;i<len;i++)
            vis[c[i]-'a']++;

         ll temp=p[len];
         for(int i=0;i<26;i++)
            temp/=p[vis[i]];
         if(temp<pos)
         {
             printf("Case %d: Impossible\n",++ca);
             continue;
         }
         //printf("temp=%lld\n",temp);
         printf("Case %d: ",++ca);
         dfs(len,pos);
         printf("\n");
     }
   return 0;
}





V-Mamba:2D 选择性扫描状态空间模型图像分类 V-Mamba CIFAR-10 分类链路:32² RGB → Stem Conv (3→64ch, stride2→16²) → VMambaBlock ×4 (SS2D 四方向 → Mamba S6 扫描 → MLP) → GAP → Linear → 10 类。核心贡献:SS2D 四方向扫描将 2D 空间建模转为 4 个 1D 序列, 计算复杂度从 O(N²) 降至 O(N)。建议先从 CIFAR-10 dim=64 depth=4 验证 SSM 收敛性; 阅读详情

相关推荐

《联邦学习实战》杨强 读书笔记十四——构建公平的大数据交易市场

当数据具有资产属性之后,数据便可以直接或者间接地为公司、为社会创造价值和收益,并且可以作为一种特殊的商品在市场中进行交易。 与传统的商品交易相比,数据资产交易的市场前景更广阔,但同时也面临着很多的挑战,主要包括: 数据的质量、价格如何定义 在合法合规的前提下,数据的交易如何确保不会泄露用户的隐私 如何构建合理的激励机制来鼓励更多的参与方加入数据交易市场中 大数据交易 数据交易的定义 数据交易是指一种对数据进行买卖的行为,大数据交易由三方共同参与,分别为数据提供方、大数据交易平台和数据需求方:

IEEE802_11的博客 3432

lightoj 1060 - nth Permutation(逆康拓展开)

Given a string of characters, we can permute the individual characters to make new strings. At first we order the string into alphabetical order. Then we start permuting it. For example the string 'a

SSimpLe_Y的博客 1128

Python爬虫实战:如何优雅地处理BOSS直聘的反爬机制与Cookie失效问题

本文详细介绍了如何通过Python爬虫技术优雅应对BOSS直聘的反爬机制与Cookie失效问题。从多账号轮换、动态请求头生成到代理IP管理,提供了一套完整的解决方案,帮助开发者构建稳定高效的数据采集系统,有效提升爬虫成功率与数据质量。

weixin_30733003的博客 1562

light oj 1060 - nth Permutation(组合数)@

1060 - nth Permutation     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Given a string of characters, we can permute the individu

MR CODER 362

电力电子新手必看:COT控制模式的工作原理与典型应用场景解析

本文深入解析了COT控制模式的工作原理及其在电力电子领域的典型应用。COT控制(恒定导通时间控制)通过固定导通时间机制,解决了传统滞环控制的问题,特别适用于需要快速瞬态响应和高效率的应用场景,如CPU/GPU供电和便携设备电源管理。文章详细介绍了COT控制的核心流程、技术特点及设计实践中的关键考量,帮助电力电子新手快速掌握这一技术。

weixin_30745553的博客 521

ubuntu20.04开机黑屏卡在/dev/sda1:clean,***files,***blocks,解决心得记录

这个问题如果你百度,会发现目前有很多种解决方法。 有更新显卡驱动的,有卸载上一次安装软件的,还有各种奇奇怪怪的故障原因。 如果你是属于上述情况,那么按照百度和论坛的各种指引操作一般都能解决。 但我这里主要说一种特殊情况,就是我什么也没有操作,我什么也没干。就是正常使用系统关了机突然就报错了。 这也是自己亲自遇到的问题,做个小记录方便以后自己回顾。 上一次出现这种情况我重装系统了,这次用了两个月又出现了,重装成本太高,我接受不了,于是找到解决办法。 首先找个终端进入,进入终端的方法很多,用安装u盘

qq_41517017的博客 2万+

LightOJ 1060-第k个排列【数学+模拟】 难度:***

题意: Given a string of characters, we can permute the individual characters to make new strings. At first we order the string into alphabetical order. Then we start permuting it. For example the string...

weixin_42921101的博客 194

CentOS7全隔离环境部署Nvidia Tesla A100 40G驱动与CUDA工具包实战

本文详细介绍了在CentOS7全隔离环境下部署Nvidia Tesla A100 40G显卡驱动与CUDA工具包的实战经验。通过构建本地YUM仓库、解决驱动依赖问题以及三重验证法,确保Tesla A100与CUDA 11.7的完美兼容。同时分享了Anaconda3离线部署技巧,帮助用户在隔离环境中高效搭建Python GPU开发环境。

weixin_27215337的博客 399

LightOJ - 1060 nth Permutation(计数)

题目大意:给你一个字符串,问这个字符串的字典序排第n的字符串是什么解题思路:计数问题,依此判断每一位即可#include <cstdio> #include <cstring> using namespace std; typedef long long LL; const int N = 30;LL A[N]; int cnt[N]; char str[N], ans[N]; LL k; int

静静地码 704

Android CCodec (十七) 硬件解码调用分析-1(基于V4l2)

简单的分析V4L2DecodeComponent和其相关内容,后续针对解码调用单独分析。

给大佬递杯卡布奇诺的博客 6593

汽车标定技术(七)--英飞凌TC3xx_Overlay实现页切换

今天说要开个专栏讲讲XCP标定,但在将标定之前,先把英飞凌专门为标定功能设计overlay功能讲解清楚。

认真搞搞汽车MCU 4015

HDU 4770 Lights Against Dudely

Problem Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money." Hagrid: "Well there's your money, Harry! Gringotts, the wizard bank! Ain't no safer place. Not

左眼皮跳跳 1655

PyTorch深度学习实战(3)——使用PyTorch构建神经网络

PyTorch 是一个用于构建深度神经网络的库,具有灵活性和可扩展性,可以轻松自定义模型。在本节中,我们将使用 PyTorch 库构建神经网络,利用张量对象操作和梯度值计算更新网络权重,并利用 Sequential 类简化网络构建过程,最后还介绍了如何使用 save、load 方法保存和加载模型,以节省模型训练时间。

盼小辉丶的博客 8万+

HDU 5325 Crazy Bobo(思路+dfs 记忆化)

Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 612    Accepted Submission(s): 189 Problem Description Bobo has a tree,

左眼皮跳跳 1209

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

hiho一下 第三十周 小Hi小Ho的惊天大作战:扫雷·一

#1114 : 小Hi小Ho的惊天大作战:扫雷·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 故事背景:密室、监视器与充满危机的广场 “我们还是循序渐进,先来考虑这样一个简单化问题:”小Hi思索片刻,道:“在一个大小为2*N的广场,其中第一行里的某一些格子里可能会有至多一个地雷,而第二行的格子里全都为数字,

左眼皮跳跳 1118

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

poj 1321 棋盘问题(dfs)

Language: Default 棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23127   Accepted: 11478 Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋

左眼皮跳跳 1089

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

zoj 3811 Untrusted Patrol(dsf+并査集+邻接表)

ZOJ Problem Set - 3811 Untrusted Patrol Time Limit: 3 Seconds      Memory Limit: 65536 KB Edward is a rich man. He owns a large factory for health drink production. As a matter of course,

左眼皮跳跳 1087

HDU 4414 Finding crosses(dfs)

Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in southern Peru. They were designated as a UNESCO World Heritage Site in 1994. The high, arid platea

左眼皮跳跳 1074

POJ 1856 Sea Battle(dfs)

POJ 1856 Sea Battle(dfs)

左眼皮跳跳 1025

HDU 2614 Beat (dfs)

HDU 2614 Beat (dfs) 题的难度与做题顺序有关

左眼皮跳跳 1003

POJ 3895 Cycles of Lanes (dfs)

最大联通环 POJ 3895 Cycles of Lanes (dfs+邻接表)

左眼皮跳跳 972

hdu 1181 变形课

hdu 1181 变形课 搜索 或者最短路(条条大道通罗马)

左眼皮跳跳 948

POJ Collecting Beepers (dfs 深度搜索)

POJ Collecting Beepers (dfs 深度搜索)

左眼皮跳跳 939

Codeforces Round #297 (Div. 2) E Anya and Cubes

E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to fold and stick. Today she d

左眼皮跳跳 929

POJ 3187 Backward Digit Sums(dfs)

POJ 3187 Backward Digit Sums(dfs)

左眼皮跳跳 912

HDU 2504 Wang Xifeng's Little Plot (dfs 或者bfs)

Problem Description 《Journey to the West》(also 《Monkey》) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty. In this novel, Monkey

左眼皮跳跳 897
上一篇: HDU 5444 Elven Postman(dfs)
下一篇: Light oj 1068 - Investigation(数位dp)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值