嘤嘤嘤,因为最近文化课老师追的紧了+班主任开班会,所以这博客是赶制的赝品

题目:

You've got a string a1,a2,…,ana1,a2,…,an, consisting of zeros and ones.

Let's call a sequence of consecutive elements ai,ai + 1,…, ajai,ai + 1,…, aj (1≤ i≤ j≤ n1≤ i≤ j≤ n) a substring of string aa.

You can apply the following operations any number of times:

  • Choose some substring of string aa (for example, you can choose entire string) and reverse it, paying xx coins for it (for example, «0101101» →→ «0111001»);
  • Choose some substring of string aa (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying yy coins for it (for example, «0101101» →→ «0110001»).

You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.

What is the minimum number of coins you need to spend to get a string consisting only of ones?

Input

The first line of input contains integers nn, xx and yy (1 ≤ n ≤ 300000,0≤x,y≤1091 ≤ n ≤ 300000,0≤x,y≤109) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).

The second line contains the string aa of length nn, consisting of zeros and ones.

Output

Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 00, if you do not need to perform any operations.

Examples

Input
5 1 10
01000
Output
11
简译:

给定一串0-1序列,定义两种操作:

  • 操作一:选取一连续子串倒置。
  • 操作二:选取一连续子串把进行01互换(取反)。
  • 并给出操作一和操作二的代价,分别为x和y。
    操作到最后要把串变成只含1的串,问最小的操作代价。

思路:

一看到这道题,脑子里想的是区间DP建立二维数组f,f[i][j]表示把i~j都转化为1的最小代价,后来因为转移方程过于复杂,且时间开销大了,所以直接放弃,然后搜了一下题解,一看标题说是假动归,我立即转向普通暴力。

读题可以了解到,1100和10是在翻转和反转下是等价的,连续的0或1可以直接转化成一个0或一个1,如11100110可以直接变为1010,这样他们的代价是一样的。然后蒟蒻提出了第一个思路:统计压缩后的0和1的数目,然后根据0和1的数目进行选择,代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
const int maxn=+,INF=0x3f3f3f3f;
int n,m,c1,a[maxn],c2,low[maxn],f[maxn],len1,len0,len;
inline int read(){
int s=,w=;
char ch=getchar();
while(ch<''||ch>''){if(ch=='-')w=-;ch=getchar();}
while(ch>=''&&ch<='') s=s*+ch-'',ch=getchar();
return s*w;
}
int main(){
//freopen("a.in","r",stdin);
n=read(),c1=read(),c2=read();
for(int i=;i<=n;i++){
char x;
cin>>x;
x-='';
if(i==||x!=a[len]){
a[++len]=x;
if(a[len]==)len1++;
else if(a[len]==)len0++;
}
}
if(len0==){
cout<<"";
return ;
}
if(len1==){
cout<<c2;return ;
}
int ans=0x3f;
if(len1<len0)cout<<min((len0-1)*c1+c2,c2*len0);
else if(len1>len0)cout<<min(len0*c1+c2,c2*len0);
else cout<<min(len0*c1+c2,c2*len0);
}

提交了发现有丶问题,这三个判断十分相似,貌似是写错了,其实可以合并,然后就改成了下面的极简代码:

 int main(){
freopen("a.in","r",stdin);
scanf("%d%d%d %s",&n,&c1,&c2,a+);
a[]='';//你问我为什么这里变成了scanf?因为提交多次发现卡死在了test4,我以为是快读beng了(遇到过卡快读的题)
for(int i=;i<=n;i++){
if(a[i-]==''&&a[i]=='')len0++;
}
if(len0==){
printf("");
}else printf("%lld",(long long)min(c1*(len0-1)+c2,c2*len0);//卡在test4的原因:不开long long
return ;
}

解释:

可以通过模拟找规律得到最后的式子

对于这个0和1分隔开的串,就结果来看,我们可以把所有的0放到一边,最后把连续的0变成1,代价为c1*(len0-1)+c2,也可以把分隔的0全部转化为1,代价为c2*len0。

然后我看了眼其他人的想法,比我的要详细一些:第一种方法,我们可以选择第二段 10 ,对其进行倒置操作,所以整个串就变成了 001101010。然后再次合并相邻的1 和相邻的0,原串变成了0101010。然后在进行一次相同的操作,就变成了 01010.以此类推,最后将变成 0 10,再倒置一次,变成 00 1,然后再对00 进行一次操作二即可。这种方法的花费为 (len0-1)*c1+c2;第二种方法,我们直接对每一段0实施操作二,使得其变为全1串,这样的花费是len0*c2(原地址https://blog.csdn.net/qq_44549690/article/details/102498866?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3(怎么这么长))

嘤嘤嘤,没了。晚上完善一下线型DP模板的题解和打地鼠的题解

【盗版动归】Codeforces998C——Convert to Ones 归一操作的更多相关文章

  1. C# 动软生成器对应的Access数据库操作类DbHelperOleDb

    using System;using System.Collections;using System.Collections.Specialized;using System.Data;using S ...

  2. 转发自:一像素 十大经典排序算法(动图演示)原链接:https://www.cnblogs.com/onepixel/articles/7674659.html 个人收藏所用 侵删

    原链接:https://www.cnblogs.com/onepixel/articles/7674659.html     个人收藏所用   侵删 0.算法概述 0.1 算法分类 十种常见排序算法可 ...

  3. 【手势交互】6. 微动VID

    中国 天津 http://www.sharpnow.com/ 微动VID是天津锋时互动科技有限公司开发的中国Leap Motion. 它能够识别并跟踪用户手部的姿态.包含:指尖和掌心的三维空间位置:手 ...

  4. apple iMac一体机 装双系统 实战! (Apple +Win 7 64bit)

    http://group.zol.com.cn/1/641_485.html http://tieba.baidu.com/p/2532811864 http://www.jb51.net/os/82 ...

  5. DDD 领域驱动设计-看我如何应对业务需求变化,愚蠢的应对?

    写在前面 阅读目录: 具体业务场景 业务需求变化 "愚蠢"的应对 消息列表实现 消息详情页实现 消息发送.回复.销毁等实现 回到原点的一些思考 业务需求变化,领域模型变化了吗? 对 ...

  6. 超越 JSON: Spearal 序列化协议简介

      Spearal 是一个新的开源的序列化协议,这个协议旨在初步替换JSON 将HTML和移动应用连接到Java的后端. Spearal的主要目的是提供一个序列协议,这个协议即使是在端点间传输的复杂的 ...

  7. Codeforces 710F String Set Quries

    题意 维护一个字符串的集合\(D\), 支持3种操作: 插入一个字符串\(s\) 删除一个字符串\(s\) 查询一个字符串\(s\)在\(D\)中作为子串出现的次数 强制在线 解法 AC自动机+二进制 ...

  8. 基于fab自动化部署

    fab是一个python库,强大好使,可以做很多帮助你减轻工作量的事情,比如在多台服务器上部署web项目,这里就讲讲使用它简单的方法来执行部署的过程. 关于fab的安装的基本使用,网上一搜一大把,内容 ...

  9. canvas动画

    1.动画主要是requestAnimationFrame方法,现在我们来一步步实现一个在画布内滚动的实例. html代码: <canvas id="canvas" width ...

随机推荐

  1. Python UI自动化测试实操

    本UI 自动化框架主要的实验的目的是:完成了登录页面的自动化登录与打开会员中心的页面这一自动化的过程. 废话不多说,直接上代码截图: 我们首先来看看整个工程的目录结构,这样以便于了解项目的调用关系: ...

  2. list基本运用

    #include<iostream> #include<list> using namespace std; list<int>list1,list2; void ...

  3. Java基础(十一)

    一.连接到服务器 telnet是一种用于网络编程的非常强大的测试工具,你可以在命令shell中输入telnet来启动它. 二.实现服务器 服务器循环体: 1.通过输入数据流从客户端接收一个命令. 2. ...

  4. Vue好书推荐

    1.Vue.js实战 从基础知识到ui组件封装和剖析,层层推进,最后两个案例实战.适合零基础入门,学完可就业.(推荐看这本) 交流地址(pdf原件):链接(点击跳转):提取码:7IsG 2.vue.j ...

  5. 4k壁纸

    4k

  6. 通过与C++程序对比,彻底搞清楚JAVA的对象拷贝

    目录 一.背景 二.JAVA对象拷贝的实现 2.1 浅拷贝 2.2 深拷贝的实现方法一 2.3 深拷贝的实现方法二 2.3.1 C++拷贝构造函数 2.3.2 C++源码 2.3.3 JAVA通过拷贝 ...

  7. Cypress系列(18)- 可操作类型的命令 之 点击命令

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 啥是可操作类型?就是可以和 DOM ...

  8. Selenium上传文件方法大全

    最好的方法:调js 其他方法: Python pywin32库,识别对话框句柄,进而操作 SendKeys库 autoIT,借助外力,我们去调用其生成的au3或exe文件. keybd_event,跟 ...

  9. range用法(倒序取值)

    range(4,-1,-1) #倒数取值 ''' start: 计数从 start 开始.默认是从 0 开始.例如range(5)等价于range(0, 5); stop: 计数到 stop 结束,但 ...

  10. CSS中可以继承的元素(需要记住)

    可以继承的属性很少,只有颜色,文字,字体间距行高对齐方式,和列表的样式可以继承. 所有元素可继承:visibility和cursor. 内联元素可继承:letter-spacing.word-spac ...