思路:

对于题目中的一个查询(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. Ionic3错误记录:navigation stack needs at least one root page

    BUG场景:在 ActionSheetController 使用modalCtrl.create 创建模态框时报如下错误 原代码片段 解决方式: 重新设置root page

  2. 采用jmeter测试dubbo服务接口

    http://www.kissyu.org/2017/02/08/jmeter%E6%B5%8B%E8%AF%95dubbo%E6%8E%A5%E5%8F%A3/

  3. 【转】基于Linux下的TCP编程

    http://blog.csdn.net/tigerjibo/article/details/6775534 一.Linux下TCP编程框架 TCP网络编程的流程包含服务器和客户端两种模式.服务器模式 ...

  4. 正则表达式的捕获组(capture group)在Java中的使用

    原文:http://blog.csdn.net/just4you/article/details/70767928 ------------------------------------------ ...

  5. Centos7最小安装下Install Clamav(2017-06-09最后更新)

    If you are installing ClamAV for the first time, you have to add a new user and group to your system ...

  6. windows 7 文件加密设置

    方法/步骤1 加密文件 1 右击需加密的文件,选择“属性”命令. 2 在属性对话框的“常规‘选项卡中单击”高级“按钮. 3 在弹出的对话框中选中”加密内容以便保护数据“复选框,单击”确定“按钮. 4 ...

  7. Smart Home DIY 计划

    工作了这么长时间了,感觉自己眼下的工作内容非常不利于技术水平的提升,对此状况,我心里深感不踏实.因此,我决定利用下班时间.边学习边做,做一套真正可用的智能家居系统,首先部署到自己居住的房间. 对此智能 ...

  8. jq 常用手册

    1.替换标签 $("img[src='/_layouts/images/lstbulet.gif']").attr("src", "/huadong/ ...

  9. struts2学习笔记(8)-------struts2的ajax支持

    struts2支持一种stream类型的Result,这样的类型的Result能够直接向client浏览器响应二进制,文本等. 我们能够再action里面生成文本响应,然后在client页面动态载入该 ...

  10. Python3.4 12306 2015年3月验证码识别

    import ssl import json from PIL import Image import requests import re import urllib.request as urll ...