注意到要字典序最小,从而变为水题。

从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的更多相关文章

  1. codeforces 724D(贪心)

    题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...

  2. 【29.41%】【codeforces 724D】Dense Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. dp小总结

    写在前面 Just some easy problem solving with dynamic programming. (Given me a dynamic programming table, ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】

    呵呵哒,上分~ CodeForces 724A: 题意: 给你两个星期几,问连续两个月的头一天是否满足: #include <iostream> #include <stdio.h& ...

  5. 漫话最小割 part1

    codeforces 724D [n个城市每个城市有一个特产的产出,一个特产的最大需求.当i<j时,城市i可以运最多C个特产到j.求所有城市可以满足最大的需求和] [如果直接最大流建图显然会T. ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. Apache Beam 传 大数据杂谈

    1月10日,Apache软件基金会宣布,Apache Beam成功孵化,成为该基金会的一个新的顶级项目,基于Apache V2许可证开源. 2003年,谷歌发布了著名的大数据三篇论文,史称三驾马车:G ...

  2. Blazor——Asp.net core的新前端框架

    原文:Blazor--Asp.net core的新前端框架 Blazor是微软在Asp.net core 3.0中推出的一个前端MVVM模型,它可以利用Razor页面引擎和C#作为脚本语言来构建WEB ...

  3. BeagleBone Black Industrial 工业版介绍

    前言 在电子发烧友论坛看到有Beaglebone Black Industrial版的试用,这里介绍一下这块开发板. BBB是开源硬件,原理图.BOM等都开放下载,所以也有诸多兼容板. BBB兼容产品 ...

  4. Intel Edison —— 控制GPIO接口,网页显示传感器数值

    前言 原创文章,转载引用务必注明链接. 因为是使用Typora(markdown)写好然后复制到论坛的,推荐直接访问我的网站以获得更好地阅读体验. Intel XDK IoT 开发环境很久之前就上手了 ...

  5. FlashBuilder找不到所需要的AdobeFlashPlayer调试器版本的解决方案

    这个问题就是因为你所装的FlashPlayer不是调试器版本.如果你的FlashPlayer是调试版,那么你随便打开一个有Flash的页面,然后右键点击Flash,就会有一个调试器,菜单,当然它现在是 ...

  6. android笔记5——同一个Activity中Fragment的切换

    今天来模拟一个注冊的界面过程: 点击"下一步"之后: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZW5zb24xNjg1NQ==/f ...

  7. Linux下VLAN功能的实现 (转)

    1.Linux网络栈下两层实现 1.1简介     VLAN是网络栈的一个附加功能,且位于下两层.首先来学习Linux中网络栈下两层的实现,再去看如何把VLAN这个功能附加上去.下两层涉及到具体的硬件 ...

  8. 文本分析实例---QQ聊天记录分析

    对QQ聊天记录进行分析,由于每天产生的聊天记录比較多,所以选取的是从2月份整月的聊天记录数据.分析要产生的结果有三个,聊天记录中发消息的人前top15.统计24小时时间段那个时间段发贴人最多,还有对消 ...

  9. 如何在外部采用AES-128对HLS的TS流进行加密

    http://www.wowza.cn/hls/howToSecureHlsByAes128External

  10. python dictionary的遍历

    d = {'x':1, 'y':3, 'z':2} for k in d:    print d[k] 直接遍历k in d的话,遍历的是dictionary的keys. 2 字典的键可以是任何不可变 ...