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

从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. 从SOA到BFV【普元的一份广告文章】

    人类对美好生活的追求是一切技术进步的原动力. 简便.快捷.联结……,这些移动互联的价值让它正成为最贴近消费者的力量.人和设备,设备和设备,人和服务,人和企业,企业和企业都发生了连接.诸如微信.携程.大 ...

  2. Regularized least-squares classification(正则化最小二乘法分类器)取代SVM

    在机器学习或者是模式识别其中有一种重要的分类器叫做:SVM .这个被广泛的应用于各个领域.可是其计算的复杂度以及训练的速度是制约其在实时的计算机应用的主要原因.因此也非常非常多的算法被提出来.如SMO ...

  3. Java安全之数字证书

    在前面说到.消息摘要用于验证数据完整性,对称与非对称加密用于保证数据保密性,数据签名用于数据的抗否认性,于是集这些安全手段于一身的终极武器--数字证书出现了.数字证书具备了加密/解密的必要信息.包括签 ...

  4. leetcode第一刷_Best Time to Buy and Sell Stock III

    这道题还是挺难的,属于我前面提到的,给个数组,线性时间找出个什么东西,尽管上面的两个买卖股票也是这类.只是相比之下稚嫩多了.有关至少至多的问题比較烦人,不好想,等再做一些题,可能会发现什么规律.这道题 ...

  5. Computer form factor

    http://en.wikipedia.org/wiki/Motherboard_form_factor Computer form factor From Wikipedia, the free e ...

  6. Hadoop源代码分析(完整版)

    Hadoop源代码分析(一) 关键字: 分布式云计算 Google的核心竞争技术是它的计算平台.Google的大牛们用了下面5篇文章,介绍了它们的计算设施. GoogleCluster:http:// ...

  7. sendmessage传递数组

    1.在初始化数组尤其是需要每次都初始化的时候,很多同学使用循环来进行,这样不但速度慢,而且写起来也很长.所以现在提供一个函数来实现这个功能... 原型:extern void *memset(void ...

  8. Tomcat 安装与配置规范

    Tomcat 安装 演示版本:8.5.32 安装版 JDK推荐版本:jdk1.8 下载地址:https://tomcat.apache.org/download-80.cgi 安装教程 注意:tomc ...

  9. 在C++中使用Libmd5计算字符串或文件的MD5值

    CppMD5Demo.cpp #include <iostream> #include <fstream> #include <chrono> #include & ...

  10. redis11----监控工具 sentinel

    当master宕机了要把slave1变为master,并把slave2指向slave1. 可以运行时更改master-slave,config set/get,修改一台slave(设为A)为new m ...