CSUOJ--1563: Lexicography
来源:互联网 发布:打印出库单软件 编辑:程序博客网 时间:2024/06/06 07:02
这个题目就是求一个序列的第k个字典序排序,因为k比较大所以我们不能穷举,而是用其它的方法求。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define ll long longchar str[20];int cc[30];ll fac[20],k;ll GetNum(int cnt){ ll ans=fac[cnt]; for(int i=0;i<26;i++) ans/=fac[cc[i]]; return ans;}void solve(int len){ for(int i=0;i<len;i++) for(int j=0;j<26;j++) { if(cc[j]) { cc[j]--; ll d=GetNum(len-i-1); cc[j]++; if(d>=k) { cc[j]--; printf("%c",'A'+j); break; } else k-=d; } }}int main(){ fac[0]=1; for(int i=1;i<=17;i++) fac[i]=fac[i-1]*i; while(scanf("%s %lld",str,&k)) { if(k==0) break; memset(cc,0,sizeof(cc)); int len=strlen(str); for(int i=0;i<len;i++) cc[str[i]-'A']++; solve(len); printf("\n"); } return 0;}
1 0
- CSUOJ--1563: Lexicography
- csuoj Lexicography
- csu 1563 Lexicography
- CSU 1563 Lexicography
- CSU 1563Lexicography
- csu 1563 Lexicography
- CSU 1563: Lexicography (数学计数问题)
- CSU 1563 Lexicography (搜索+组合数)
- CSUOJ
- CSUOJ
- CSU 1563 Lexicography(全排列第K大)
- UVALive6814 Lexicography
- CSU1563 Lexicography
- CSU1563-Lexicography
- Lexicography CSU
- CSU1563:Lexicography(数学)
- Lexicography (UVALive 6814)
- csuoj--1307
- CAS指令 incrementAndGet方法 JAVA非阻塞同步
- uitableview
- 面试:机器学习--支持向量机
- Object转XML && XML转Object
- 关于Bundle及其在不同activity之间的传值
- CSUOJ--1563: Lexicography
- Android的生命周期(三)
- opencv findContours使用问题
- 添加view
- jQuery的prop和attr方法之间区别
- 10000 pcs free gift of chinese top grade brown film faced plywood
- 参数自适应的单层 bp 神经网络
- 019:函数:我的地盘听我的
- mac 下安装android studio