codeforces 724D
注意到要字典序最小,从而变为水题。
从a选到z,每次必然是先看选部分当前字符x是否能满足覆盖,若不能则选上所有的字母x,不然break,输出答案。
进行26次dp即可。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue> #define N 100010
#define INF 0x3f3f3f3f using namespace std; struct node{
int x,v;
bool operator<(const node &a)const{
return v>a.v;
}
}; char S[N];
char ansv[N];
int n,m,tot,f[N];
priority_queue<node> q; int main(){
// freopen("D.txt","r",stdin);
scanf("%d%s",&m,S);
n=strlen(S); for(char x='a';x<='z';x++){
for(int i=;i<=n;i++) f[i]=INF;
f[]=; while(!q.empty()) q.pop();
q.push((node){,});
int cnt=; for(int i=;i<=n;i++){
if(S[i-]>x) continue;
if(S[i-]==x) cnt++; while(!q.empty()){
node tmp=q.top(); if(tmp.x<i-m) q.pop();
else{
if(S[i-] == x) f[i] = tmp.v + ;
else f[i] = tmp.v;
break;
}
} if(f[i]<INF) q.push((node){i,f[i]});
} int ans=INF;
for(int i=n-m+;i<=n;i++) ans = min(ans,f[i]); if(ans<INF){
while(ans--) ansv[++tot]=x;
break;
}
else while(cnt--) ansv[++tot]=x;
} for(int i=;i<=tot;i++) putchar(ansv[i]);
putchar('\n');
return ;
}
codeforces 724D的更多相关文章
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- 【29.41%】【codeforces 724D】Dense Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- dp小总结
写在前面 Just some easy problem solving with dynamic programming. (Given me a dynamic programming table, ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】
呵呵哒,上分~ CodeForces 724A: 题意: 给你两个星期几,问连续两个月的头一天是否满足: #include <iostream> #include <stdio.h& ...
- 漫话最小割 part1
codeforces 724D [n个城市每个城市有一个特产的产出,一个特产的最大需求.当i<j时,城市i可以运最多C个特产到j.求所有城市可以满足最大的需求和] [如果直接最大流建图显然会T. ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
随机推荐
- UItableView 所有内容保存为图片
将所有的UITableView保存为图片,因为UITableView只能保存显示当前,所以,就单个保存后,合并为一张图片 代码如下: -(IBAction)savePic:(id)sender { / ...
- 基于MNIST数据的卷积神经网络CNN
基于tensorflow使用CNN识别MNIST 参数数量:第一个卷积层5x5x1x32=800个参数,第二个卷积层5x5x32x64=51200个参数,第三个全连接层7x7x64x1024=3211 ...
- 前端高频面试题 CSS篇
通过从网上看到的面经,总结的一些高频的前端CSS面试题,有很多不会,于是找资料,并通过代码实现,自己提供了一些参考答案. 目录 1.怎样会产生浮动? 2.如何清除浮动? 3.盒子模型,以及IE和其他浏 ...
- Monkey源代码分析之事件注入
本系列的上一篇文章<Monkey源代码分析之事件源>中我们描写叙述了monkey是怎么从事件源取得命令.然后将命令转换成事件放到事件队列里面的.可是到如今位置我们还没有了解monkey里面 ...
- HTML页面底部无用留白
HTML页面底部无用留白,可以再footer样式中加入: overflow: hidden; 如有错误,请您指正~
- python 字符串前缀
普通字符串 一般字符串都是已unicode编码,且和C类似,可以使用\来转义,比如 a = "test\ntest" print(a) 输出 test test 前面加r 在字符串 ...
- 如何理解pca和svd的关系?
主成分分析和奇异值分解进行降维有何共同点? 矩阵的奇异值分解 当矩阵不是方阵,无法为其定义特征值与特征向量,可以用一个相似的概念来代替:奇异值. 通常用一种叫奇异值分解的算法来求取任意矩阵的奇异值: ...
- iOS UIButton选中状态切换
UIButton*payBtn = [UIButtonbuttonWithType:UIButtonTypeCustom]; payBtn.frame=CGRectMake(size.width-24 ...
- Ajax的简单实现(Json)
之前写的是一般的Ajax if (request.status === 200) { document.getElementById("createResult").innerHT ...
- ajax的异步操作及页面重定向跳转
今天主要分享一个简单的ajax的异步操作数据,用javascript也有一段时间了,刚开始看到一些页面在没有页面刷新的情况下就可以实现数据的保存或者获取,觉得挺不可思议的,感觉速度很快,做了几个项目之 ...