题意:https://codeforc.es/problemset/problem/1204/D2

给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 l~r 的LIS最长上升子序列长度不变)。

问:0111001100111011101000

答:0011001100001011101000

思路:

参考题解:考虑什么串无法该变。

1. 10无法被改变(我们称为固定串),00,01,11都可以改。

2. 固定串+固定串(无法被改变)。

3. 1+固定串+0(无法被改变)。

所以固定串也就是类似于:111000101100 之类的。

容易想到:固定串是可以直接删除的,比如:01+110010+1 == 00+110010+0 ,不会影响前后(而且我们发现0和1的数量相等),而且你也不可能去改固定串。

所以我们可以不断的剔除固定串。

那剩下的1就全是可以改为0的了。

问题也就转变成了一个类似括号匹配的问题,我们就从后往前记录0的个数,把能匹配10的1标记好,最后把没有标记的1变成0就行了。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; char s[N];
bool f[N]; int main()
{
int l;
s[]='$';
sc("%s",s+);
l=strlen(s)-;
int cnt=;
for(int i=l;i>=;--i)
{
if(s[i]=='')
cnt++;
else
{
if(cnt)
cnt--,f[i]=;
}
}
fo(i,,l)
if(s[i]==''&&!f[i])
s[i]='';
pr("%s\n",s+);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)的更多相关文章

  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. D1. Kirk and a Binary String (easy version)

    D1. Kirk and a Binary String (easy version) 01串找最长不降子序列 给定字符串s,要求生成一个等长字符串t,使得任意l到r位置的最长不降子序列长度一致 从后 ...

  3. Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...

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

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

  5. Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)

    A. BowWow and the Timetable time limit per test1 second memory limit per test256 megabytes inputstan ...

  6. Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)

    Problem   Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...

  7. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  8. 01背包 Codeforces Round #267 (Div. 2) C. George and Job

    题目传送门 /* 题意:选择k个m长的区间,使得总和最大 01背包:dp[i][j] 表示在i的位置选或不选[i-m+1, i]这个区间,当它是第j个区间. 01背包思想,状态转移方程:dp[i][j ...

  9. Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)

    Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...

随机推荐

  1. __new()__与__init__()

    1. __new__:创建对象时调用,会返回当前对象的一个实例.(默认情况下也就是你在类中没有没有重新这个方法,会默认返回当前类的示例,如果你重写了这个方法,但是在方法中没有返回当前类的示例,那么也就 ...

  2. 库&插件&框架&工具

    nodejs 入门 nodejs 入门教程,大家可以在 github 上提交错误 2016 年最好用的表单验证库 SMValidator.js 前端表单验证工具分享 浅谈前端线上部署与运维 说到前端部 ...

  3. linux vmware 安装步骤

    一.下载vmware软件 二.下载centos镜像文件 三.安装步骤 以上相当于于硬件设备已经准备ok,接下来安装软件

  4. 在win10系统安装两个不同版本的mySQL数据库

    我们项目用的mySQL数据库,为了回家看代码方便,于是在本地安装mySQL数据库,一开始安装了比服务器mySQL5.7.24更高版本的mySQL8.0.11,结果项目启动报错,估计是版本太高项目中引入 ...

  5. 微信小程序之生成二维码

    最近项目中涉及到小程序的生成二维码,很是头疼,经过多次摸索,整理出了自己的一些思想方法,如有不足,欢迎指正. 首先完全按照小程序的结构依次填坑. pages--index.wxml <view ...

  6. log4net保留几天内的日志

    想实现保留7天(一周)内的日志,网上一堆下述代码 <appender name="RollingLogFileAppender" type="log4net.App ...

  7. GitHub-Tech-DotNet:Cnblogs

    ylbtech-GitHub-Tech-DotNet:Cnblogs 1.返回顶部 · EnyimMemcachedCore Forked from enyim/EnyimMemcached A Me ...

  8. Zabbix - LINUX下CPU,硬盘,流量,内存监控

    转载自:https://blog.csdn.net/jxzhfei/article/details/47191431 1.LINUX下zabbix客户端安装 [root@mongodb114 ~]# ...

  9. ViewGroup的事件机制

    根据View的事件机制,再添加在代码中添加一个自定义的LinearLayout,继承LinearLayout,然后复写了与事件分发机制有关的方法,日志输出 import android.content ...

  10. 数据库开源框架之GreenDAO

    主页: https://github.com/greenrobot/greenDAO 配置: 添加以下依赖 * compile 'de.greenrobot:greendao:2.1.0' * com ...