lightoj1060【康托逆展开】
2024-08-30 08:29:14
可以先看些资料:http://blog.csdn.net/keyboarderqq/article/details/53388936
参考谷巨巨:http://blog.csdn.net/azx736420641/article/details/50982142
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
//const int mod=1e9+7;
const int INF=0x3f3f3f3f; char s[25];
LL f[25];
int a[30]; void init()
{
f[0]=1;
for(int i=1;i<=22;i++)
f[i]=f[i-1]*i;
} int main()
{
init();
int n,T,len,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%s%d",s,&n);
len=strlen(s);
memset(a,0,sizeof(a));
for(int i=0;i<len;i++)
a[s[i]-'a']++;
//计算总的方案数,采用除序法;
LL temp=f[len];
for(int i=0;i<26;i++)
temp/=f[a[i]];
printf("Case %d: ",cas++);
if(temp<n)
{
puts("Impossible");
continue;
} for(int i=0;i<len;i++)
{
for(int j=0; j<26; j++)
{
if(!a[j])
continue;
a[j]--;
LL tmp=f[len-i-1]; //对于第i个位置为j,计算总排列数
for(int k=0; k<26; k++) //除序法计算方案数
tmp/=f[a[k]];
if(n<=tmp) //如果方案数已超,一定是字母 j ;
{
printf("%c",'a'+j);
break;
}
n-=tmp; //减去,肯定是别的字母
a[j]++;
}
}
puts("");
}
return 0;
}
最新文章
- Spring Framework------>;version4.3.5.RELAESE----->;Reference Documentation学习心得----->;使用spring framework的IoC容器功能----->;方法一:使用XML文件定义beans之间的依赖注入关系
- Handler的总结
- Java学习第五天
- JavaScript中,{}+{}等于多少?
- android的intent打开系统程序
- Jedis超时时间设置梳理
- Windows上Python2与Python3共存
- capwap学习笔记——初识capwap(三)(下)
- tensorboard 可视化网络运行过程
- .net core 2.0 webuploader上传图片
- vue监听滚动事件 实现某元素吸顶或者固定位置显示
- zookeeper各种报错、原因及解决方法汇总(持续更新)
- 编程,计算data段中的第一组数据的3次方,结果保存在后面一组dword单元中
- ps和fireworks切图网页优化,jpg为80时
- 【基于初学者的SSH】struts2 的拦截器、令牌的简单应用及理解
- XP系统下建立WIFI热点让手机、电脑能上网
- 三种方案在Windows系统下安装ubuntu双系统
- Html5实现iPhone开机界面
- 开发者应该了解的API技术清单
- Stars(树状数组单点更新)
热门文章
- android handler looper
- 网络直播流媒体协议的选择讨论,RTSP,RTMP,HTTP,私有协议?
- mybatis入门(十)
- SpringBoot-(4)-Filter的使用
- (转)windows下一分钟配置ngnix实现HLS m3u8点播
- Appnium安装-Mac平台
- 关于<;context:annotation-config/>;配置
- spring+mybatis项目整合
- Gradients渐变属性
- hibernate入门(-)