思路:

对于题目中的一个查询(m, c),枚举子区间[l, r](0 <= l <= r < n),若该区间满足其中的非c字符个数x不超过m,则可以将其合法转换为一个长度为r-l+1的全c子序列,可以使用动态规划以O(n2)的复杂度计算,然而O(n2q)的复杂度还是太高了。于是先离线把26n中情况都计算出来,再打表即可。复杂度O(26n2+q)。

实现:

 #include <iostream>
#include <cstdio>
using namespace std; const int MAXN = ; int n, q, m, ans[][MAXN];
string s;
char c; int main()
{
cin >> n >> s;
for (int k = ; k < ; k++)
{
char tmp = 'a' + k;
for (int i = ; i < n; i++)
{
int cnt = ;
for (int j = i; j < n; j++)
{
if (s[j] != tmp) cnt++;
ans[k][cnt] = max(ans[k][cnt], j - i + );
}
}
for (int i = ; i < MAXN; i++)
ans[k][i] = max(ans[k][i], ans[k][i - ]);
}
cin >> q;
for (int i = ; i < q; i++)
{
scanf("%d %c", &m, &c);
printf("%d\n", ans[c - 'a'][m]);
}
}

CF814C An impassioned circulation of affection的更多相关文章

  1. An impassioned circulation of affection

    An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 mega ...

  2. 【Codeforces Round 418】An impassioned circulation of affection DP

                                                            C. An impassioned circulation of affection   ...

  3. codeforces 814 C. An impassioned circulation of affection 【尺取法 or DP】

    //yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想. 题目链接:codeforces 814 C. An impassioned circulation of ...

  4. Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection

    C. An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 m ...

  5. An impassioned circulation of affection(尺取+预处理)

    题目链接:http://codeforces.com/contest/814/problem/C 题目: 题意:给你一个长度为n的字符串,m次查询,每次查询:最多进行k步修改,求字符c(要输入的字符) ...

  6. C. An impassioned circulation of affection DP

    http://codeforces.com/contest/814/problem/C 12ooyomioomioo21 o2 o 这题我是用dp解的,不过好像很慢,比赛的时候算了下不会mle,就没滚 ...

  7. 【尺取或dp】codeforces C. An impassioned circulation of affection

    http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...

  8. codeforces 814 C. An impassioned circulation of affection(二分+思维)

    题目链接:http://codeforces.com/contest/814/problem/C 题意:给出一串字符串然后q个询问,问替换掉将m个字符替换为字符c,能得到的最长的连续的字符c是多长 题 ...

  9. Codeforces 814C - An impassioned circulation of affection

    原题链接:http://codeforces.com/contest/814/problem/C 题意:有长度为n的一个字符串,q个询问,每个询问由数字m和字符c组成,问最多在字符串中替换m个字符,使 ...

随机推荐

  1. HTML5 全屏化操作功能

    由于项目中用到了全屏化挫折功能,查看了API后写了一个简单的全屏化model <!DOCTYPE html> <html> <head> <meta http ...

  2. 洛谷 P2064 奇妙的汽车

    P2064 奇妙的汽车 题目描述 你有着一辆奇妙的汽车,这辆汽车有着自动加速的功能.打个比方吧,第1天你驾驶着它可以行驶a路程,那么第2天你可以让它所走的路程增加到第1天的2~9倍(必须是其中一个整数 ...

  3. JDBC的存储过程

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/stored-procedure.html: 正如一个Connection对象创建了Statement和 ...

  4. CSS3的animation功能

    旋转动画 <img src="https://facebook.github.io/react/img/logo.svg" class="App-logo" ...

  5. C#写的NoSQL开源项目/系统(系列)

    http://www.cnblogs.com/unruledboy/archive/2013/01/07/CSharpNoSQL.html 闲扯 好久没写开源项目了,也没写对新开源项目的介绍,今晚看了 ...

  6. nodejs连接sqlserver

    nodejs连接sqlserver http://blog.csdn.net/kkkkkxiaofei/article/details/31353091

  7. [Maid] Write Tasks in Markdown with Maid

    Maid enables you to write your tasks in Markdown. Create a maidfile.md or a README.mdthen add Header ...

  8. RAD 极速应用开发 Spring ROO 入门样例

    官网                                      http://projects.spring.io/spring-roo/ Spring ROO in action   ...

  9. restlet 2.3.5 org.restlet包导入eclipse出现的com.sun.net.httpserver类包找不到问题

    准备过一遍restlet 2.3.5 JavaEE的源码. 环境 eclipse3.7.2 和 jdk 7.0 将org.restlet 包增加到eclipse中.出现 com.sun.net.htt ...

  10. 图像处理之基础---yuv420及其rgb,bayer, yuv, RGB的相互转换详解

    YUV格式解析1(播放器——project2) 根据板卡api设计实现yuv420格式的视频播放器 打开*.mp4;*.264类型的文件,实现其播放. 使用的视频格式是YUV420格式   YUV格式 ...