D1. Kirk and a Binary String (easy version)
D1. Kirk and a Binary String (easy version)
01串找最长不降子序列
给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致
从后往前暴力枚举,枚举每个一替换成0后是否改变了l到r位置的最长不降子序列长度
01串的最长不降子序列,可以通过线性dp求解
dp i表示以i结尾的最长不降子序列长度
dp[0]=dp[0]+s[i]=='0';
dp[1]=max(dp[0],dp[1])+s[i]=='1';
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sc(x) scanf("%I64d",&(x));
typedef long long ll;
#define maxn 2005 #define INF 1e18
ll N;
ll val[][maxn];
ll dp[];
void LIS(string s,int st,int val[])
{
dp[]=dp[]=;
for(int i=st;i<N;i++){
if(s[i]==''){
dp[]++;
}else dp[]=max(dp[],dp[])+;
val[i]=max(dp[],dp[]);
} }
signed main()
{
string s,t;
cin>>s;
N=s.size();
t=s;
//int len=0;
for(int i=N-; i>=;i--)
{
if(s[i]=='')
{
t[i]='';
LIS(s,i,val[]);
LIS(t,i,val[]);
for(int j=i;j<N;j++){
if(val[][j]!=val[][j]){
t[i]='';
break;
}
}
}
}
cout<<t<<'\n';
}
下面这个大概思路是从后往前枚举,后面的0个数比1个数小时,可以删当前位置1
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sc(x) scanf("%I64d",&(x));
typedef long long ll;
#define maxn 2005 #define INF 1e18
ll N;
ll val[][maxn];
ll dp[];
void LIS(string s,int st,int val[])
{
dp[]=dp[]=;
for(int i=st;i<N;i++){
if(s[i]==''){
dp[]++;
}else dp[]=max(dp[],dp[])+;
val[i]=max(dp[],dp[]);
} }
signed main()
{
string s,t;
cin>>s;
N=s.size();
t=s;
int cnt=;
for(int i=N-; i>=;i--)
{
if(s[i]==''){
cnt++;
}else if(cnt==&&s[i]==''){
t[i]='';
}else cnt--;
}
cout<<t<<'\n'; }
D1. Kirk and a Binary String (easy version)的更多相关文章
- D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)
D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...
- Codeforces 1204D2. Kirk and a Binary String (hard version) (dp思路)
题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl ...
- 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)
题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...
- CF1204D Kirk and a Binary String
题目链接 problem 给出一个长度为\(n(n\le 10^5)\)的只包含01的字符串.把尽可能多的1变为0,使得对于所有的\(l \in [1,n],r\in [l,n]\),区间\([l,r ...
- Codeforces 1204D Kirk and a Binary String - 数学
题目传送门 传送门 群除我均会猜结论/找规律,sad.... 以下内容只保证代码能过system test,证明应该都是在纯口胡 约定下文中的$LIS$表示最长不下降子序列. 定义$zero(s)$表 ...
- CF #579 (Div. 3) D1.Remove the Substring (easy version)
D1.Remove the Substring (easy version) time limit per test2 seconds memory limit per test256 megabyt ...
- Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...
- Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】
任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...
- E1. String Coloring (easy version)(贪心)
E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes ...
随机推荐
- eclipse 或 STS 卸载SVN 插件
help菜单 ==> about eclipse ==>install details按钮 ==> installed software选项卡 选中下面的这几项,点击 uni ...
- 八、Zabbix-应用集、监控项
一.应用集 1.应用集一般配合监控项使用,它相当于多个同类型的监控项的分类目录 2.添加应用集 (1)配置—>模板—>需要调整的模板—>应用集 (2)添加应用集 (3) (4)查看应 ...
- 第六周总结&第四次实验报告
实验四 类的继承 一. 实验目的 (1) 掌握类的继承方法: (2) 变量的继承和覆盖,方法的继承.重载和覆盖实现: 二. 实验内容 三.实验过程 实验代码 package Shiyan4; publ ...
- vue中的provide和inject
vue中的provide和inject:https://blog.csdn.net/viewyu12345/article/details/83011618
- Spring Task 任务调度(定时器)
1.任务调度SpringTask 1.1什么是任务调度 在企业级应用中,经常会制定一些“计划任务”,即在某个时间点做某件事情,核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作.常见的 ...
- The order of a Tree
The order of a Tree Problem Description As we know,the shape of a binary search tree is greatly rela ...
- neo4j 初探
neo4j 初探 参考 转载:http://shomy.top/2018/06/08/neo4j-start/ 近期需要处理图数据,考察后打算使用neo4j, 相比其他一些图数据库,neo4j开源,跨 ...
- go & flag
参考 Golang下的flag模块使用 Go基础篇[第6篇]: 内置库模块 flag
- thinkphp5 隐藏前台入口文件index.php 后台入口文件admin.php不隐藏
情景:应用目录下有两个模块 admin(后台) 和 home(前台) 需求:1.访问前台(home)时隐藏index.php 即 域名/home/前台控制器/前台控制器里的方法 这样的访问模式 2. ...
- jQuery进阶第二天(2019 10.10)
一.事件流程 1.事件的三要素: 事件源:发生事件的对象 事件类型:类型比如单击.双击.鼠标的移入.移除 事件处理程序: 触发事件之后做些什么,事件处理的函数 <body> <but ...