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 ...
随机推荐
- [DS+Algo] 009 树的介绍
目录 1. 树的概念 2. 树的术语 3. 树的种类 4. 常见应用场景 5. 二叉树 1. 树的概念 每个结点(节点)有 0 个或多个子结点 没有父结点的结点称为根结点 每一个非根结点有且只有一个父 ...
- 关于android工具链
1 android sdk platform tools 同android platform交互的工具,包括adb.fastboot和systrace. 2 sdk build tools 用于bui ...
- numpy数组的运算
numpy数组的运算 数组的乘法 >>> import numpy as np >>> arr=np.array([[1,2,3],[4,5,6]]) >&g ...
- [2019多校联考(Round 6 T3)]脱单计划 (费用流)
[2019多校联考(Round 6 T3)]脱单计划 (费用流) 题面 你是一家相亲机构的策划总监,在一次相亲活动中,有 n 个小区的若干男士和 n个小区的若干女士报名了这次活动,你需要将这些参与者两 ...
- python UnicodeEncodeError: 'gbk' codec can't encode character ...
使用Python写文件的时候,或者将网络数据流写入到本地文件的时候,大部分情况下会遇到:UnicodeEncodeError: 'gbk' codec can't encode character ' ...
- Python 实用脚本
Python 实用脚本 脚本写的好,下班下得早!程序员的日常工作除了编写程序代码,还不可避免地需要处理相关的测试和验证工作. 例如,访问某个网站一直不通,需要确定此地址是否可访问,服务器返回什么,进而 ...
- spring boot 枚举使用的坑
java 枚举的功能挺多,但是坑更多,使用的时候要注意.如下面这个枚举. @Getter @AllArgsConstructor public enum EnumExpenseType impleme ...
- [七月挑选]使用hexo建立主题,并发布到github
title: 使用hexo建立主题,并发布到github 根据hexo官网的概述和hexo官网的建站,搭建最开始的hexo博客. 1.环境预先安装好node.js和git 2.npm安装hexo: $ ...
- bak文件恢复成 SQL2005 数据库 的全程讲解
经常会碰到客户给我们发的是一个bak的数据库备份文件,而不是一个数据库.这就需要我们把这数据文件还原成数据库的形式. 如将demo.bak数据库恢复到mssql2005下 打开SQL2005,打开后就 ...
- mailto - 简单多媒体邮件发送程序
SYNOPSIS mailto [-a] [-c] [-s] [recipient name(s)] DESCRIPTION mailto 程序是一个用于发送MIME格式的多媒体邮件(MIME格式是 ...