CF-Codeforces Round #418 (Div. 2)-C-An impassioned circulation of affection
来源:互联网 发布:网络电视台客户端 编辑:程序博客网 时间:2024/06/05 23:44
ACM模版
描述
题解
对于这种海量查询的问题,不用多想,99 成需要预处理,而常见的预处理手段除了线段树、树状数组、RMQ 之类,还有 DP 等等,这里用的就是 DP 预处理。
设
其他就没有什么可说的了~~~
代码
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAXN = 1555;const int MAXC = 26;int n, q;char str[MAXN];int dp[MAXC][MAXN];int main(){ while (cin >> n) { memset(dp, 0, sizeof(dp)); scanf("%s", str); for (int i = 0; i < MAXC; i++) { for (int j = 0; j <= n; j++) { dp[i][j] = j; } } for (int i = 0; i < n; i++) { int c = str[i] - 'a'; int tmp = 1, k = i + 1; dp[c][0] = 1; for (int j = 0; j <= n; ) { if (k >= n || str[i] != str[k]) { j++; } tmp++; if (tmp == n) { while (j <= n) { dp[c][j++] = n; } break; } dp[c][j] = max(dp[c][j], tmp); k++; } } cin >> q; int m; char c[3]; while (q--) { scanf("%d%s", &m, c); printf("%d\n", dp[c[0] - 'a'][m]); } } return 0;}
阅读全文
0 0
- CF-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(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) C. An impassioned circulation of affection 预处理
- Codeforces Round #418 C--An impassioned circulation of affection
- 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 814C An impassioned circulation of affection
- codeforces 814C An impassioned circulation of affection
- codeforces 814 C An impassioned circulation of affection
- Codeforces 814C-An impassioned circulation of affection
- python super()和classmethod
- xml文件读取到数据库
- R语言连接数据库汉字乱码问题
- Spring Cloud Netflix之Eureka Doc Translation
- Java设计模式笔记之组合模式
- CF-Codeforces Round #418 (Div. 2)-C-An impassioned circulation of affection
- 读SDWebImage库系列(1)-如何保证同一时间请求相同URL时,只进行一次网络请求
- Unity Shader入门精要笔记(一):渲染流水线
- [leetcode]: 617. Merge Two Binary Trees
- jackson反序列化时忽略不需要的字段
- 数组操作--增、删、改、查
- IO流
- 51Nod--1019 逆序数
- Activity的生命周期