[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 ...
随机推荐
- 设置 SSH 命令行空闲保持会话
楔子 使用 Mac 或 Linux 原生的命令行 ssh user@ip 方式连接 Linux 闲时会自动断开终端卡死. 为解决这个问题,查了到篇博客翻译下关键步骤记录下来.解决方式可以分服务端设置和 ...
- 前端规范之Git工作流规范(Husky + Comminilint + Lint-staged)
代码规范是软件开发领域经久不衰的话题,几乎所有工程师在开发过程中都会遇到或思考过这一问题.而随着前端应用的大型化和复杂化,越来越多的前端团队也开始重视代码规范.同样,前段时间,笔者所在的团队也开展了一 ...
- The type name or alias SqlServer could not be resolved.Please check your configuration
The type name or alias SqlServer could not be resolved.Please check your configuration file.... 检查一下 ...
- Java基础之(五):数据类型
Java快捷键 首先我们先来介绍下IDEA的一些快捷键 psvm=public static void main(String[] args) {} sout=System.out.println(& ...
- 题解 CF736D Permutations
link Description 现在,你有一个二分图,点数为 \(2n\). 已知这个二分图的完备匹配的个数是奇数. 现在你要知道,删除每条边后,完备匹配个数是奇数还是偶数. \(1\le n\le ...
- 洛谷3203 弹飞绵羊(LCT)
据说这个题当年的正解是分块qwq 根据题目所说,对于题目中的弹力系数,就相当于一条边,那么对于"跳出去"这个限制,我们可以选择建造一个新点\(n+1\)表示结束,那么每次,求一个点 ...
- vue3.x异步组件
在大型应用中,我们可能需要将应用分割成小一些的代码块,并且只在需要的时候才从服务器加载一个模块 vue2.x 曾经简单的异步组件 components: { AsyncComponent: () =& ...
- Java Filter型内存马的学习与实践
完全参考:https://www.cnblogs.com/nice0e3/p/14622879.html 这篇笔记,来源逗神的指点,让我去了解了内存马,这篇笔记记录的是filter类型的内存马 内存马 ...
- 全连接层dense作用
参考来源
- 【SDOI2014】数数(补)
见 AC自动机(补坑了) [SDOI2014] 数数 简要题意: 我们称一个正整数N是幸运数,当且仅当它的十进制表示中不包含数字串集合S中任意一个元素作为子串.例如当S={22,333,0233}时 ...