题目大意

给出整数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]++;
}
}
}

Codeforces Round #387 (Div. 2) 747F(数位DP)的更多相关文章

  1. Educational Codeforces Round 53 E. Segment Sum(数位DP)

    Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...

  2. Codeforces Round #131 (Div. 2) B. Hometask dp

    题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...

  3. Educational Codeforces Round 8 D. Magic Numbers 数位DP

    D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the deci ...

  4. Codeforces Round #131 (Div. 1) B. Numbers dp

    题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...

  5. Codeforces Round #276 (Div. 1) D. Kindergarten dp

    D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...

  6. Codeforces Round #260 (Div. 1) A - Boredom DP

    A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A ...

  7. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  8. Codeforces Round #539 (Div. 2) 异或 + dp

    https://codeforces.com/contest/1113/problem/C 题意 一个n个数字的数组a[],求有多少对l,r满足\(sum[l,mid]=sum[mid+1,r]\), ...

  9. Codeforces Round #374 (Div. 2) C. Journey DP

    C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to o ...

随机推荐

  1. iOS MapKit地图

    地图框架:#import <MapKit/MapKit.h> 基本属性和方法: 属性: 地图类视图:MKMapView 地图类型:MKMapType mapType 地图旋转:rotate ...

  2. ES6初识- Class

    { //基本定义和生成实例 class Parent{ //构造函数 constructor(name='lisi'){ this.name=name; } //属性get,set get longN ...

  3. JavaScript提高容错的方式

    项目环境为Java Web项目,前端多用jquery,记录碰到的JS提高容错的编写方式. 回调的数据为null,数据绑定过程报错,影响下面代码执行 这种情况一开始想到的是能不能改用前端框架来动态的对页 ...

  4. elasticsearch-dsl笔记

    一.elasticsearch安装 安装java1.8以上 安装elasticsearch-rtf(https://github.com/medcl/elasticsearch-rtf) head插件 ...

  5. js | javascript中获取dom元素的高度和宽度

    javascript中获取dom元素高度和宽度的方法如下: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网 ...

  6. Linux用户与组管理命令

    1.列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可. who | cut -d" " -f1 | sort -u 或 who | cut -d ...

  7. Guava Cache 工具类 [ GuavaCacheUtil ]

    pom.xml <dependency> <groupId>com.google.guava</groupId> <artifactId>guava&l ...

  8. Windows Server 2008 IIS 并发请求设置

    更新服务器的时候,突然发现部分机器出现了错误,大致描述如下 HTTP Error 503.2 - Service Unavailable 正在超过 serverRuntime@appConcurren ...

  9. linux基础命令3(man)

    Type:显示指定的命令是那种类型.                                            Linux下有两种模式的时间 date:用于系统时间管理.(软件操作的系统时 ...

  10. 亲手搭建一个基于Asp.Net WebApi的项目基础框架3

    1:使用Framework工具类封装http请求 接上第二篇的步骤,现在在站点中使用封装好的组件,将framework编译好之后把dll提取出来,然后放到lib当中 在website中引用dll 接下 ...