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)的更多相关文章

  1. 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 ...

  2. Codeforces 1204D2. Kirk and a Binary String (hard version) (dp思路)

    题目链接:http://codeforces.com/contest/1204/problem/D2 题目是给定一个01字符串,让你尽可能多地改变1变为0,但是要保证新的字符串,对任意的L,R使得Sl ...

  3. 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)

    题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...

  4. 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 ...

  5. Codeforces 1204D Kirk and a Binary String - 数学

    题目传送门 传送门 群除我均会猜结论/找规律,sad.... 以下内容只保证代码能过system test,证明应该都是在纯口胡 约定下文中的$LIS$表示最长不下降子序列. 定义$zero(s)$表 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. E1. String Coloring (easy version)(贪心)

    E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes ...

随机推荐

  1. [LeetCode] 1090. Largest Values From Labels

    使用 Java 爬取 LeetCode 题目内容以及提交的AC代码 传送门 Description We have a set of items: the i-th item has value va ...

  2. 配置DHCP中继

    本实验模拟企业网络场景.某公司分部的网络由交换机S1和网关路由器R1组成,员工终端PC-1和PC-2都连接在S1上.公司要求分部内所有员工主机的IP地址都通过总部的DHCP服务器自动获取.分部网关路由 ...

  3. Java 5种单例模式

    /*单例模式: 指某个类中只能存在一个对象实例,并且该类中只提供一个取得其对象实例的方法 优点:减少系统性能开销 应用场景:网站的计数器,任务管理器,回收站等*/   //单例模式1 -- 静态内部类 ...

  4. cqoj921E整数匹配

    这是一个贪心题,把我坑的好惨,忘还原得70.上午被卡得,, 首先给出长度为n的一组数,可以两两配对相乘也可以进行相加,问怎样才可以使总和最大?那么可以显然看出来,当这个数为0或1时,我们要相加.其余进 ...

  5. [LeetCode] 103. 二叉树的锯齿形层次遍历

    题目链接 : https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/ 题目描述: 给定一个二叉树,返回其节 ...

  6. HNUSTOJ-1258 Time

    1258: Time 时间限制: 1 Sec  内存限制: 128 MB提交: 16  解决: 11[提交][状态][讨论版] 题目描述 Digital clock use 4 digits to e ...

  7. div的edit和drag(点击div可编辑、删除、拖动)

    1.可编辑: <div id="move" contentEditable="true">可编辑</div> 设置contentEdit ...

  8. UIDynamic物理引擎

    iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟 ...

  9. delete释放空间时出错的原因

    int *a=new int[10]; ...... delete []a; 后面“delete []a;”出现错误的情况大致有: 1 数组的首地址a被你有意无意更改了,如:a++之类的: 2 变量的 ...

  10. Oracle锁表信息处理步骤

    查看是否有锁表的sql select 'blocker(' || lb.sid || ':' || sb.username || ')-sql:' || qb.sql_text blockers, ' ...