CF 997A
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;
}
CF 997A的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
随机推荐
- Jquery Ajax Post Json
var markers = { "markers": [ { "position": "128.3657142857143", " ...
- Python——8函数式编程①
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- Mybatis笔记01-基本原理,配置文件,映射文件,以及调用过程
Mybatis基本原理 应用程序找Mybatis要数据 mybatis从数据库中找来数据 2.1 通过mybatis-config.xml 定位哪个数据库 2.2 通过Category.xml执行对应 ...
- Python——五分钟带你弄懂迭代器与生成器,夯实代码能力
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是周一Python专题,给大家带来的是Python当中生成器和迭代器的使用. 我当初第一次学到迭代器和生成器的时候,并没有太在意,只是觉 ...
- 06 Linux 的常用命令
Linux 刚面世时并没有图形界面,所有的操作全靠命令完成,如 磁盘操作.文件存取.目录操作.进程管理.文件权限 设定等 在职场中,大量的 服务器维护工作 都是在 远程 通过 SSH 客户端 来完成的 ...
- php不用第三个变量,交换两个数的值
//字符串版本 结合使用substr,strlen两个方法实现 $a="a"; $b="b"; echo '交换前 $a:'.$a.',$b:'.$b.'< ...
- Gorm 预加载及输出处理(一)- 预加载应用
单条关联查询 先创建两个关联模型: // 用户模型 type User struct { gorm.Model Username string `gorm:"type:varchar(20) ...
- python第一次作业
import turtle turtle.pensize(2) turtle.pencolor("black") turtle.fillcolor("red") ...
- OpenMP Programming
一.OpenMP概述 1.OpenMP应用编程接口API是在共享存储体系结构上的一个编程模型 2.包含 编译制导(compiler directive).运行库例程(runtime library). ...
- MySQL记录操作(多表查询)
准备 建表与数据准备 #建表 create table department( id int, name varchar(20) ); create table employee( id int pr ...