[hdu7044]Fall with Fake Problem
二分$T$和$S$第一个不同的位置,即需要对于$s$,判定是否存在$T[1,s]=S[1,s]$且满足条件的$T$
(注:这里的条件不包含$T$的字典序最小)
显然$T[1,s]$已经确定,记其中第$i$种字母出现次数为$a_{i}$
而对于$T(s,n]$,只有字典序(尽量大)和字符数量的限制,因此若交换两个字符能增大字典序显然不劣,重复交换这样的字符,不难得到最终字符从前往后是不上升的
设其中第$i$种字符有$b_{i}$个,即希望依次最大化$b_{26},b_{25},...,b_{1}$,不妨依次暴力枚举(共$\sigma(k)$种取值),并对后面的部分背包+bitset判定是否可行,即可得到该序列并进而比较与$S$的字典序
这一部分的复杂度为$o(\alpha\sigma(k)\frac{n}{\omega}\log n)$(其中$\alpha=26$,$\omega=64$)
进一步的,由于下一个位置一定不同,那么再之后的部分也仅有字典序(尽量小)和字符数量的限制,可以类似地求出,而下一个位置直接暴力枚举即可
这一部分的复杂度为$o(\alpha^{2}\sigma(k)\frac{n}{\omega})$
综上,(单组数据)复杂度为$o(\alpha\sigma(k)\frac{n}{\omega}\log n+\alpha^{2}\sigma(k)\frac{n}{\omega})$,可以通过


1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 100005
4 #define A 26
5 vector<int>v;
6 bitset<N>bt[A+1];
7 int t,n,m,a[A],b[A];
8 char s[N];
9 bool get_max(int n){
10 memset(b,0,sizeof(b));
11 for(int i=A-1;i>=0;i--){
12 bt[i].reset();
13 for(int j=0;(j<v.size())&&(a[i]<=v[j]);j++){
14 int x=v[j]-a[i];
15 if (x<=n)bt[i]|=(bt[i+1]<<x);
16 }
17 }
18 if (!bt[0][n])return 0;
19 for(int i=0;i<A;i++)
20 for(int j=0;(j<v.size())&&(a[i]<=v[j]);j++){
21 b[i]=v[j]-a[i];
22 if ((b[i]<=n)&&(bt[i+1][n-b[i]])){
23 n-=b[i];
24 break;
25 }
26 }
27 return 1;
28 }
29 bool check(int k){
30 memset(a,0,sizeof(a));
31 for(int i=1;i<=k;i++)a['z'-s[i]]++;
32 if (!get_max(n-k))return 0;
33 for(int i=0;i<A;i++)
34 for(int j=0;j<b[i];j++)
35 if (s[++k]!='z'-i)return s[k]<'z'-i;
36 return 1;
37 }
38 int main(){
39 bt[A][0]=1;
40 scanf("%d",&t);
41 while (t--){
42 scanf("%d%d%s",&n,&m,s+1);
43 v.clear();
44 for(int i=m;i;i--)
45 if (m%i==0)v.push_back(i);
46 v.push_back(0);
47 memset(a,0,sizeof(a));
48 if (!check(0)){
49 printf("-1\n");
50 continue;
51 }
52 int l=0,r=n;
53 while (l<r){
54 int mid=(l+r+1>>1);
55 if (check(mid))l=mid;
56 else r=mid-1;
57 }
58 if (l==n){
59 printf("%s\n",s+1);
60 continue;
61 }
62 memset(a,0,sizeof(a));
63 for(int i=1;i<=l;i++)a[s[i]-'a']++;
64 for(int i=s[l+1]-'a'+1;i<A;i++){
65 a[i]++;
66 if (get_max(n-l-1)){
67 for(int j=1;j<=l;j++)printf("%c",s[j]);
68 printf("%c",i+'a');
69 for(int j=0;j<A;j++)
70 while (b[j]--)printf("%c",j+'a');
71 printf("\n");
72 break;
73 }
74 a[i]--;
75 }
76 }
77 return 0;
78 }
[hdu7044]Fall with Fake Problem的更多相关文章
- IOS UITableView分组与索引分区实例
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- Problem of saving images in WPF (RenderTargetBitmap)zz
To save a visual to an image file need to use RenderTargetBitmap, detail is reference to Save and ...
- fake gucci outlet perform a couple associated with things in great trust
Based on my a lot of years of encounter within Taobao, purchase bags must go to the high reputation ...
- Google Code Jam 2010 Round 1A Problem A. Rotate
https://code.google.com/codejam/contest/544101/dashboard#s=p0 Problem In the exciting game of Jo ...
- Bag Problem
Bag Problem Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/131072 K (Java/Others) Total ...
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- C#学习日志 day10 -------------- problem statement
Revision History Date Issue Description Author 15/May/2015 1.0 Finish most of the designed function. ...
- 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem D. Grumpy Cat 交互题
Problem D. Grumpy Cat 题目连接: http://www.codeforces.com/gym/100253 Description This problem is a littl ...
随机推荐
- dg create datafile auto failed 排除处理
1.Environment:11.2.0.4 dg 2.Symptoms:告警描述:Wed Sep 22 14:29:15 2021Errors in file /data/app/oracle/di ...
- HTML模板标签解析
HTML基本模板 1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4 <meta cha ...
- TWAIN-v2.4-说明文档翻译(2)技术概览
技术概览 Technical Overview TWAIN架构(TWAIN Architecture) 数据交互的实现在TWAIN中由三类软件元素共同工作完成:应用程序(the application ...
- Rafy 框架 - 实体支持只更新部分变更的字段
Rafy 快一两年没有大的更新了.并不是这个框架没人维护了.相反,主要是因为自己的项目.以及公司在使用的项目,都已经比较稳定了,也没有新的功能添加.但是最近因为外面使用了 Rafy 的几个公司,找到我 ...
- 《手把手教你》系列技巧篇(三十一)-java+ selenium自动化测试- Actions的相关操作-番外篇(详解教程)
1.简介 上一篇中,宏哥说的宏哥在最后提到网站的反爬虫机制,那么宏哥在自己本地做一个网页,没有那个反爬虫的机制,谷歌浏览器是不是就可以验证成功了,宏哥就想验证一下自己想法,于是写了这一篇文章,另外也是 ...
- Java初步学习——2021.10.05每日总结,第五周周三
(1)今天做了什么: (2)明天准备做什么? (3)遇到的问题,如何解决? 今天学了对象与类,如何定义类和创建对象,以及构建方法的用法. 明天课比较多,把今天未学的例子敲一遍好了. 没有遇到什么问题.
- Python&Selenium 数据驱动测试【unittest+ddt+xml】
一.摘要 本博文将介绍Python和Selenium做自动化测试时,基于unittest框架,借助ddt模块,使用xml文件作为测试输入. 二.xml文件 保存路径:D:\\Programs\\Pyt ...
- kafka应用讲解及应用场景(三)
一. 验证 1.进入bin目录 cd bin 2.ls查看脚本 会发现下面有很多脚本文件,由于我是要创建一个topic所有直接打开kafka-topics.sh脚本查看命令 打开脚本后发现里面有很多命 ...
- [BUAA]起点 软工第一次作业-热身
项目 内容 这个作业属于哪个课程 2020计算机学院软件工程(罗杰 任健) 这个作业的要求在哪里 第一次作业-热身! 我在这个课程的目标是 了解软件开发,提高自己的工程能力和团队协作能力 这个作业在哪 ...
- 热身训练2 The All-purpose Zero
The All-purpose Zero 简要题意: 长度为n的数组,每个数字为S[i],$0$是一种很神奇的数字,你想要的,它都可以变! 问这个序列的最长上升子序列长度为多少? 分析: 我们将除了 ...