You’ve got a string a1,a2,…,an, consisting of zeros and ones.
Let’s call a sequence of consecutive elements ai,ai + 1,…, aj (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
Choose some substring of string a (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 y 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?

。。。懒得弄格式了凑合看吧 我好随便

分析

  求最小花费让整个字符串变成1,看到最小花费,是不是想到了Dp,想到Dp就条坑里去了,用Dp的话,你会发现状态没法转移,因为它既涉及到了区间反转,又涉及到了区间更新。

  两种操作还要分类讨论,很麻烦,这两种操作有什么内在联系呢?手动模拟一下会发现,反转一段区间,可以将两段0合并成一段,而区间更新没有限制,除了是一段连续区间外,所以,反转区间和合并区间的操作是等价的,故如果有k段0需要处理,可以先将它们合并成1段,再集中处理,最后一次更新区间肯定是要用的,因为0不可能平白无故变成1,所以讨论一下k-1次处理的选择方式就好,显然是取最小值,因为答案让求最小嘛。

 #include<iostream>
const int N=3e5+;
char a[N];
using namespace std;
int main(){
int n,x,y;
cin>>n>>x>>y>>a+;
long long cnt=0ll;
a[]='';
for(int i=;i<=n;i++)
if(a[i]==''&&a[i-]=='')
cnt++;
if(cnt==)cout<<;
else cout<<(cnt-)*min(x,y)+y;
}

最新文章

  1. C语言 &#183; 整数平均值
  2. springmvc整合fastjson
  3. python del 注意点
  4. [NSURLSession/Delegate]用Post方式获取网络数据并把数据显示到表格
  5. android_view自定义中的几个方法
  6. Redrain个人维护并使用的DuiLib和UiLib库源代码下载地址
  7. IDEA 从SVN检出项目相关配置
  8. WIN10 ANDROIDSTUDIO1.2 安装完首次启动报错
  9. js获取页面高度赋值给div
  10. [Angular2 Router] CanActivate Route Guard - An Example of An Asynchronous Route Guard
  11. lightoj 1020 (博弈)
  12. nginx查看日志
  13. BAE 环境下配置 struts2 + spring + hibernate(SSH)(二)struts2
  14. Android中的创建型模式总结
  15. &lt; welcome &gt; 一起学习,进步,分享。
  16. 平均时间复杂度为O(nlogn)的排序算法
  17. &lt;canvas合成海报&gt;所遇问题及解决方案总结
  18. JMX与Spring
  19. VxWorks启动过程详解(下)
  20. DateTime Tips

热门文章

  1. 【WPF学习】第五十章 故事板
  2. Kubernetes搭建过程中使用k8s.gcr.io、quay.io、docker.io的镜像加速
  3. C++走向远洋——24(项目一,三角形,复制构造函数)
  4. Swift --闭包表达式与闭包(汇编分析)
  5. &lt;select&gt;标签,不要在select标签中写value属性!!!
  6. DirectX11--深入理解Effects11、使用着色器反射机制(Shader Reflection)实现一个复杂Effects框架
  7. flask 对于邮件url进行一个加密防止爆破
  8. 简单配置Vue路由
  9. 浅谈Java中静态代码块和非静态代码块
  10. Overt.GrpcTemplate.Service 模板使用教程