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 ...
随机推荐
- oracle内核学习总结
http://blog.csdn.net/bcbobo21cn/article/category/3092145/1
- ftp服务器调用出错
因工作需要,需从FTP服务器上下载文件,本地测试OK,服务器上在FTP服务器连接之后卡住,没有异常和提示信息,在打印FTP命令之后,显示:150 Opening data channel for fi ...
- 浏览器g.xxx333xxx.com 跳转2345问题解决方法
近期升级windows10系统我,我顺手在浏览器输入"windows10"激活keyword,下载了小马激活工具进行了激活.例如以下图. 下载安装后.浏览器每次打开强制跳转到234 ...
- 走入asp.net mvc不归路:[1]项目文件结构
先来了解一下一个asp.net mvc项目的文件结构. 1 项目文件结构一览 2 mvc,顾名思义,一个项目中最重要的就是这三个东西:M(Model,模型),V(View,视图),C(Controll ...
- js 监控浏览器关闭(完美兼容chrome & ie & fire fox)
var UnloadConfirm = {}; UnloadConfirm.MSG_UNLOAD = "数据尚未保存,离开后可能会导致数据丢失\n\n您确定要离开吗?"; Unlo ...
- WPF窗口最大化
做C/S应用程序的过程中,要实现的一个功能是可以编辑系统某一类表,这些表又含有不同的properties,properties数量也不相同,有二十来个的,也有一两个的,所以,popUp出来之后大小各异 ...
- Posix信号量操作函数
Posix信号量: 分类: Posix有名信号量:使用Posix IPC名字标识,可用于线程或进程间同步Posix基于内存的信号量:存放在共享内存区中,可用于进程或线程间的同步 sem_open(). ...
- Cocos2d-x学习资源
1.CSDN博客:http://blog.csdn.net/legendof1991/article/category/2161091.主要讲的Cocos2d-x3.0 2.CSDN博客:http:/ ...
- Linux和Windows设备驱动架构比较
毕业后一直在学操作系统, 有时候觉得什么都懂了,有时候又觉得好像什么都不懂,但总体来说自认为对操作系统实现机制的了解比周围的人还是要多一些.去年曾花了几个星期的晚上时间断断续续翻译了这篇对Linux和 ...
- openwrt 配置rsync服务
一: rsyn简介 remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限.时间.软硬链接等附加信息. rsync是用 “rsyn ...