题目大意

给出整数k和t,需要产生一个满足以下要求的第k个十六进制数

即十六进制数每一位上的数出现的次数不超过t

首先我们先这样考虑,如果给你了0~f每个数字可以使用的次数num[i],如何求长度为L且满足要求的十六进制数有多少个

dp[i][l]表示使用了前i个数字,已经将L的空位填上了l个的数有多少个

转移方程 dp[i][l] = sigma(dp[i-1][l-j]*C[len-l+j[j]) 其中j是枚举填新的数的个数,C是组合数(选出j个空位填上新数)

有了这个dp后,现在的问题就变成了找出第k个数

首先先确定位数,枚举位数,然后就可以找到第k个数的位数是多少

然后对从最高位开始枚举,确定每一位应该是多少

最后就可以得出答案

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
const int maxl = ;
LL C[maxl][maxl], dp[][maxl];
int num[], t;
LL k;
void prepare()
{
for(int i = ; i < maxl; i++) C[i][] = ;
for(int i = ; i < maxl; i++)
for(int j = ; j <= i; j++)
C[i][j] = C[i-][j] + C[i-][j-];
} LL solve(int len)
{
memset(dp, , sizeof(dp));
for(int i = ; i <= num[]; i++) dp[][i] = C[len][i];
for(int i = ; i < ; i++)
for(int l = ; l <= len; l++)
for(int j = ; j <= min(num[i], l); j++)
dp[i][l] += dp[i-][l-j]*C[len-l+j][j];
return dp[][len];
}
void print(int j)
{
if(j < ) cout<<j;
else cout<<(char)(j+'a'-);
}
int main()
{
prepare();
cin>>k>>t;
for(int i = ; i < ; i++) num[i] = t;
int len = ;
for(;; len++)
{
LL tmp = ;
if(len == ) tmp = ;
else
for(int j = ; j < ; j++)
{
num[j]--;
tmp += solve(len-);
num[j]++;
}
if(k > tmp) k -= tmp;
else break;
}
for(int i = len; i > ; i--)
{
if(i == )
{
for(int j = ; j < ; j++)
{
if(j == && len == ) continue;
if(num[j] != ) k--;
if(k == ) { print(j); break; }
}
break;
}
for(int j = ; j < ; j++)
{
if(i == len && j == ) continue;
num[j]--;
LL tmp = solve(i-);
if(k > tmp) k -= tmp;
else
{
print(j);
break;
}
num[j]++;
}
}
}

最新文章

  1. LayoutControl让一个控件占据多行或者多列
  2. OC/Swift第三方添加出错解决方法
  3. 392. Is Subsequence
  4. 如何实现批处理文件传参数给SQLPLUS
  5. MS-DOS命令列表
  6. 问题汇总-20130927-关于rc.local命令无法执行
  7. 第二章实例:Android窗口菜单显示
  8. asp脱离源代码管理
  9. ContentPlaceHolderID属性
  10. C#获取本机局域网ip和公网ip
  11. redis 安装时候遇到 jemalloc 问题记录
  12. day20 hashlib、hmac、subprocess、configparser模块
  13. 软件光栅器实现(二、VS和PS的运作,法线贴图,切空间的计算)
  14. 关于three.js中添加文字的方式[转]
  15. hdu 3033(好题,分组背包)
  16. canvas - drawImage()方法绘制图片不显示的问题
  17. Halcon中二维码解析函数解码率和时长的优化方法
  18. MGR Switch single-Primary to Muti_primary
  19. PHP的输出方式
  20. 字符串截取,SubString

热门文章

  1. iOS面试题总结(持续更新)
  2. mybatis中oracle转mysql
  3. MySQL 5.7基于GTID的主从复制环境搭建(一主一从)
  4. 分享spring、spring boot、spring cloud一些学习资源,从基础知识到项目实战
  5. form表单submit按钮提交页面不跳转
  6. 使用windows api安装windows服务程序(C#)
  7. tp5 使用技巧(持续更新中...)
  8. php扩展开发-INI配置
  9. linux ipc信号量
  10. PAT (Basic Level) Practice 1040 有几个PAT