The Preliminary Contest for ICPC Asia Shanghai 2019 F. Rhyme scheme(dp)


题意:给你一个n和k 要你找到长度为n 字典序第k小的字符串 定义一个字符串合法:第i的字符的范围只能是前i-1个字符中的最大值+1
思路:我们dp[n][i][j]表示长度为n 在第i位 最大值为j的序列有多少个 随后我们可以直接模仿找第k大一样找到第k个字符串
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int N = 1e6+7;
typedef long long ll;
typedef __int128 bll;
const ll mod = 998244353;
using namespace std;
inline __int128 read() {
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void print(__int128 x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) print(x/10);
putchar(x%10+'0');
}
bll dp[30][30][30];
char v[30];
bll dfs(int len,int now,int mx){
if(now==len){
dp[len][now][mx]=1;
return dp[len][now][mx];
}
if(dp[len][now][mx]!=-1) return dp[len][now][mx];
bll ans=0;
for(int i=1;i<=min(mx+1,26);i++){
if(i<=mx){
ans+=dfs(len,now+1,mx);
}else{
ans+=dfs(len,now+1,i);
}
}
dp[len][now][mx]=ans;
return ans;
}
int main(){
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
int t; scanf("%d",&t);
for(int i=0;i<30;i++)
for(int j=0;j<30;j++)
for(int k=0;k<30;k++)
dp[i][j][k]=-1;
for(int i=1;i<=26;i++)
dfs(i,1,1);
int w=0;
// print(dp[3][1][1]);
while(t--){
int n; scanf("%d",&n);
bll k; k=read();
int mx=1;
printf("Case #%d: ",++w);
for(int i=1;i<=n;i++){
v[i]='A';
for(int j=1;j<=mx+1;j++){
//cout<<k<<" "<<dp[n][i][j]<<endl;
int p=max(mx,j);
if(dp[n][i][p]>=k){
// mx=max(mx,j);
v[i]=char(j+'A'-1);
//putchar('A' + j - 1);
mx=max(mx,p);
// cout<<j<<endl;
break;
}else{
k-=dp[n][i][p];
}
}
}
for(int i=1;i<=n;i++)
printf("%c",v[i]);
puts("");
}
return 0;
}
The Preliminary Contest for ICPC Asia Shanghai 2019 F. Rhyme scheme(dp)的更多相关文章
- The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力)
The Preliminary Contest for ICPC Asia Shanghai 2019 C Triple(FFT+暴力) 传送门:https://nanti.jisuanke.com/ ...
- The Preliminary Contest for ICPC Asia Shanghai 2019
传送门 B. Light bulbs 题意: 起初\(n\)个位置状态为\(0\),\(m\)次操作,每次操作更换区间状态:\(0\)到\(1\),\(1\)到\(0\). 共有\(T,T\leq 1 ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 C. Triple
[传送门] FFT第三题! 其实就是要求有多少三元组满足两短边之和大于等于第三边. 考虑容斥,就是枚举最长边,另外两个数组里有多少对边之和比它小,然后就是 $n^3$ 减去这个答案. 当 $n \le ...
- 01背包方案数(变种题)Stone game--The Preliminary Contest for ICPC Asia Shanghai 2019
题意:https://nanti.jisuanke.com/t/41420 给你n个石子的重量,要求满足(Sum<=2*sum<=Sum+min)的方案数,min是你手里的最小值. 思路: ...
- 给定进制下1-n每一位数的共享(Digit sum)The Preliminary Contest for ICPC Asia Shanghai 2019
题意:https://nanti.jisuanke.com/t/41422 对每一位进行找循环节规律就行了. #define IOS ios_base::sync_with_stdio(0); cin ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 A. Lightning Routing I
传送门 因为某些原因,所以我就去学了 $LCT$ 维护直径, $LCT$ 维护直径我上一个博客讲得很详细了:传送门 这里维护虚儿子用的是 $multiset$ ,没写可删堆 #include<i ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum
题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; ][]= ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 J. Stone game
题目:https://nanti.jisuanke.com/t/41420 思路:当a(a∈S′)为最小值 如果Sum(S′)−a≤Sum(S−S′)成立 那么(∀t∈S′,Sum(S′)−t≤Sum ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 D. Counting Sequences I
题目:https://nanti.jisuanke.com/t/41412思路:dfs 先取ai>2 2^12>3000 因此至多取11个 其余用1补 ...
随机推荐
- 【MyBatis】MyBatis 入门
MyBatis 入门 文章源码 软件框架 软件框架伴随着软件工程的发展而出现,所谓的软件框架,是提取了特定领域的软件的共性部分所形成的软件体系,它并不是一个成熟的软件,更像是一个半成品.开发者在框架之 ...
- 剑指 Offer 16. 数值的整数次方
实现函数double Power(double base, int exponent),求base的exponent次方.不得使用库函数,同时不需要考虑大数问题. 来源:力扣(LeetCode) 链接 ...
- apiAutoTest: 接口自动化测试的数据清洗(备份/恢复)处理方案
接口自动化测试之数据清洗/隔离/备份/恢复 在得到QQ:1301559180 得代码贡献之后,想到了通过ssh连接上服务器,然后进行数据库备份,数据库恢复, 主要使用了 paramiko库 最终效果 ...
- 环境变量IFS
环境变量IFS的值是由1个空格.1个制表符.1个换行符依序构成的字符串,也就是" \t\n"字符串. #查看IFS变量值的长度: test ~ # expr length &quo ...
- service代理模式及负载均衡
[root@k8s-master ~]# vim service.yaml apiVersion: v1 kind: Service metadata: name: my-service spec: ...
- 24V降压5V芯片,5A,4.5V-30V输入,同步降压调节器
PW2205开发了一种高效率的同步降压DC-DC转换器5A输出电流.PW2205在4.5V到30V的宽输入电压范围内工作集成主开关和同步开关,具有非常低的RDS(ON)以最小化传导损失.PW2205采 ...
- 如何在 Blazor WebAssembly中 使用 功能开关
微软Azure 团队开发的 功能管理 (Feature Management) 包 Microsoft.FeatureManagement可用于实现 功能开关,可以通过 功能开关 特性动态的改变应用程 ...
- 第2章_神经网络入门_2-5&2-6 数据处理与模型图构建
目录 神经元的TF实现 安装 神经网络的TF实现 神经元的TF实现 安装 版本: Python 2.7 tf 1.8.0 Linux 略 demo 神经网络的TF实现 # py36 tf 2.1. # ...
- response返回特性
1. response 返回特性 r=requests.get("http://www.baidu.com")print(r.text) #打印返回正文print(r.status ...
- 如果using语句中出现异常,资源会被释放掉吗?
<CLR Via C#>第三版 P489 在using内部抛出了异常,被using的对象还是会被释放掉. Using编译时会自动生成Try Finally代码块. 同样Using只能用于实 ...