Codeforces Round #418 (Div. 2) -- C. An impassioned circulation of affection(DP预处理)
来源:互联网 发布:校园招聘java面试题库 编辑:程序博客网 时间:2024/06/05 20:30
题意:
给你一个字符串, 告诉你喜欢的字母,和改变字母的次数,求在次数内 在长连续喜欢字母的长度?
思路:
直接令dp[i][j] 表示改变i 次,喜欢字母为j 的最大长度。
直接n*n*26预处理即可。
#include <bits/stdc++.h>using namespace std;const int maxn = 1500 + 10;char s[maxn];int dp[maxn][30];int main(){ int n; scanf("%d",&n); scanf("%s", s); int len = strlen(s); for (int i = 0; i < 26; ++i){ for (int j = 0; j < n; ++j){ int sum = 0; for (int k = j; k < len; ++k){ if (s[k] == i+'a')++sum; dp[k-j+1-sum][i] = max(dp[k-j+1-sum][i], k-j+1); } } } int q; scanf("%d",&q); char cmd[3]; while(q--){ int x,y; scanf("%d%s",&x, cmd); int ans = 0; for (int i = 0; i <= x; ++i){ ans = max(ans, dp[i][cmd[0]-'a' ]); } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- Codeforces Round #418 (Div. 2) -- C. An impassioned circulation of affection(DP预处理)
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection 预处理
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection(尺取)
- Codeforces Round #418 (Div. 2) 814 C. An impassioned circulation of affection
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection
- Codeforces Round #418 (Div. 2)C.An impassioned circulation of affection(暴力枚举)
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection
- CF-Codeforces Round #418 (Div. 2)-C-An impassioned circulation of affection
- Codeforces Round #418 C--An impassioned circulation of affection
- Codeforces 814C An impassioned circulation of affection【Dp】
- Codeforces 814C An impassioned circulation of affection (dp)
- Codeforces 814C An impassioned circulation of affection(dp)
- CF Round #418( Div.2) An impassioned circulation of affection
- codeforces C. An impassioned circulation of affection
- Codeforces#418 An impassioned circulation of affection
- Codeforces#418C An impassioned circulation of affection
- codeforces 814 C. An impassioned circulation of affection(暴力)
- codeforces 418div2 C. An impassioned circulation of affection(尺取)
- Servlet
- 同步锁效率低的例子
- rand()和srand()函数
- android:内存泄露与内存溢出区别、内存泄露定位
- LINUX摄像驱动三:从零开始写虚拟驱动
- Codeforces Round #418 (Div. 2) -- C. An impassioned circulation of affection(DP预处理)
- 从端到云——工业物联网项目全栈快速开发实践
- 清除行列
- 并查集详解 (转)
- unity中使用配置文件进行参数设置
- linux输出九九乘法表
- IIC实例的SDA_In和SDA_Out的代码理解GPIOB->MODER&=~(3<<(9*2));GPIOB->MODER|=0<<9*2;
- Java生成图片验证码
- Win7(64Bit) 安装 PL/SQL Developer图解