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 ...
随机推荐
- __new__ 和 __init__
new 在新式类中负责真正的实例化对象,而__init__只是负责初始化 __new__创建的对象.一般来说 new 创建一个内存对象,也就是实例化的对象的实体,交给__init__进行进一步加工.官 ...
- 关于使用uitableview 中cell 来实现uiimageview的复用和图片的异步加载
apple sample lazytableimages 1,首先设置横向显示的uitableview self.customTableview.transform = CGAffineTransfo ...
- go使用时间作为种子生成随机数
原文:http://blog.csdn.net/qq_15437667/article/details/50851159 --------------------------------------- ...
- 配置 yum 源相关
1. 修改yum配置 http://www.cnblogs.com/shuaixf/archive/2011/11/30/2268496.html 2. centos安装 epel 源 https:/ ...
- 转:一个android开发者独立开发社交app全过程
http://www.cnblogs.com/linguanh/p/5683069.html
- node 爬虫 --- 批量下载图片
步骤一:创建项目 npm init 步骤二:安装 request,cheerio,async 三个模块 request 用于请求地址和快速下载图片流. https://github.com/reque ...
- background-size使用参考指南
语法:background-size :[ <length> | <percentage> | auto ]{1,2} | cover | contain相关属性: backg ...
- 【转载】C# sleep 和wait的区别
eep和wait都是使线程暂时停止执行的方法,但它们有很大的不同. 1. sleep是线程类Thread 的方法,它是使当前线程暂时睡眠,可以放在任何位置. 而wait,它是使当前线程暂时放弃对象的使 ...
- 2015-03-12---外观模式,建造者模式(附代码),观察者模式(附代码),boost库应用
今天白天主要看了boost库的应用,主要是经常使用的一些库,array,bind,function,regex,thread,unordered,ref,smartpointers库,晚上看了看设计模 ...
- CA与数字证书的自结
1.CA CA(Certificate Authority)是数字证书认证中心的简称,是指发放数字证书.管理数字证书.废除数字证书的权威机构. 2.数字证书 如果向CA申请数字证书的单位为A.则他申请 ...