C. Gas Pipeline
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment [0,n][0,n] on OXOX axis. The road can have several crossroads, but for simplicity, we'll denote each crossroad as an interval (x,x+1)(x,x+1) with integer xx. So we can represent the road as a binary string consisting of nn characters, where character 0 means that current interval doesn't contain a crossroad, and 1 means that there is a crossroad.

Usually, we can install the pipeline along the road on height of 11 unit with supporting pillars in each integer point (so, if we are responsible for [0,n][0,n] road, we must install n+1n+1 pillars). But on crossroads we should lift the pipeline up to the height 22, so the pipeline won't obstruct the way for cars.

We can do so inserting several zig-zag-like lines. Each zig-zag can be represented as a segment [x,x+1][x,x+1] with integer xx consisting of three parts: 0.50.5 units of horizontal pipe + 11 unit of vertical pipe + 0.50.5 of horizontal. Note that if pipeline is currently on height 22, the pillars that support it should also have length equal to 22 units.

Each unit of gas pipeline costs us aa bourles, and each unit of pillar — bb bourles. So, it's not always optimal to make the whole pipeline on the height 22. Find the shape of the pipeline with minimum possible cost and calculate that cost.

Note that you must start and finish the pipeline on height 11 and, also, it's guaranteed that the first and last characters of the input string are equal to 0.

Input

The fist line contains one integer TT (1≤T≤1001≤T≤100) — the number of queries. Next 2⋅T2⋅T lines contain independent queries — one query per two lines.

The first line contains three integers nn, aa, bb (2≤n≤2⋅1052≤n≤2⋅105, 1≤a≤1081≤a≤108, 1≤b≤1081≤b≤108) — the length of the road, the cost of one unit of the pipeline and the cost of one unit of the pillar, respectively.

The second line contains binary string ss (|s|=n|s|=n, si∈{0,1}si∈{0,1}, s1=sn=0s1=sn=0) — the description of the road.

It's guaranteed that the total length of all strings ss doesn't exceed 2⋅1052⋅105.

Output

Print TT integers — one per query. For each query print the minimum possible cost of the constructed pipeline.

Example
input

Copy
4
8 2 5
00110010
8 1 1
00110010
9 100000000 100000000
010101010
2 5 1
00
output

Copy
94
25
2900000000
13
Note

The optimal pipeline for the first query is shown at the picture above.

The optimal pipeline for the second query is pictured below:

The optimal (and the only possible) pipeline for the third query is shown below:

The optimal pipeline for the fourth query is shown below:

题意:管道工人需要在一段凹凸不平的道路上铺管子,给一串长度为n的01序列描述地形,1表示一定要把水管用钢管架高在离地面2个单位,0表示水管离地面高度可以为1,也可以为2,

在转折的地方需要额外花费1单位的水管,给定水管和钢管的价格a,b;问最少需要花费多少钱

#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define mx 0x3f3f3f3f3f3f3f
#define ll long long
#define MAXN 100
using namespace std;
ll dp[][];
char s[];
ll n,a,b,t;
int main()
{
cin>>t;
while(t--)
{
cin>>n>>a>>b;
scanf("%s",s+);
for(int i=;i<=n;i++)//初始化dp
{
dp[i][]=mx;
dp[i][]=mx;
}
dp[][]=b;
dp[][]=mx;
for(int i=;i<=n;i++)
{
if(s[i]=='')//高柱子的右边一定是长度为2的管子
dp[i][]=min(dp[i][],dp[i-][]+a+b*);
else//低柱子的右边可能是长度为1的,也可能是长度为2的管子,两者取更小的花费
{
dp[i][]=min(dp[i][],min(dp[i-][]+a+b,dp[i-][]+*a+b));
dp[i][]=min(dp[i][],min(dp[i-][]+*a+*b,dp[i-][]+a+b*));
}
}
cout<<dp[n][]<<endl;
}
return ;
}

C. Gas Pipeline DP的更多相关文章

  1. [贪心,dp] Educational Codeforces Round 71 (Rated for Div. 2) C. Gas Pipeline (1207C)

    题目:http://codeforces.com/contest/1207/problem/C   C. Gas Pipeline time limit per test 2 seconds memo ...

  2. Codeforces 1207C Gas Pipeline (dp)

    题目链接:http://codeforces.com/problemset/problem/1207/C 题目大意是给一条道路修管道,相隔一个单位的管道有两个柱子支撑,管道柱子高度可以是1可以是2,道 ...

  3. Educational Codeforces Round 71

    https://www.cnblogs.com/31415926535x/p/11460682.html 上午没课,做一套题,,练一下手感和思维,,教育场的71 ,,前两到没啥,,后面就做的磕磕巴巴的 ...

  4. 第9周cf刷题(dp)

    Problems(1300-1600) an ac a day keeps the doctor away Gas Pipeline (1500) 2019.10.28 题意: 管道工人需要在一段凹凸 ...

  5. Educational Codeforces Round 71 (Rated for Div. 2)

    传送门 A.There Are Two Types Of Burgers 签到. B.Square Filling 签到 C.Gas Pipeline 每个位置只有"高.低"两种状 ...

  6. Educational Codeforces Round 71 (Rated for Div. 2) Solution

    A. There Are Two Types Of Burgers 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...

  7. CF Edu Round 71

    CF Edu Round 71 A There Are Two Types Of Burgers 贪心随便模拟一下 #include<iostream> #include<algor ...

  8. PAT甲级考前整理(2019年3月备考)之一

       转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...

  9. 一份程序猿单词列表(updating)

    以下单词是个人平时阅读英文文档时遇到的一些“生”单词,该文档将持续更新,可以持续关注https://github.com/hylinux1024/word-list-for-programmer hi ...

随机推荐

  1. 再见2018,你好2019 -- 致 Mac 背后的自己

    转眼间 2018 年即将过去,心有万千感慨,真的感觉到时间如白驹过隙,成长没有跟上时间的脚步,这叫老了一岁,如果跟上了,那就叫成熟了一岁.很遗憾,2018年我老了一岁. 新年之初,立过好几个 Flag ...

  2. Centos 7源码编译安装 php7.1 之生产篇

    Centos 7源码编译安装 php7.1 之生产篇 Published 2017年4月30日 by Node Cloud 介绍: 久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具 ...

  3. Python爬虫教程:requests模拟登陆github

    1. Cookie 介绍 HTTP 协议是无状态的.因此,若不借助其他手段,远程的服务器就无法知道以前和客户端做了哪些通信.Cookie 就是「其他手段」之一. Cookie 一个典型的应用场景,就是 ...

  4. QGridLayout栅格布局函数参数设置

    对于PyQt5的栅格布局函数,主要是实现多个控件之间的栅格布局形式,一般有两种设置方式: 1.Qdesigner布局设置时直接使用栅格布局函数,便可以把所需要布局的控件直接按照栅格方式来进行布局: 2 ...

  5. WinForm开发(2)——DataGridView控件(2)——C# dataGridview控件,怎么获取行数

    dataGridView1.Rows.Count;//所有行数dataGridView1.RowCount;//可见行数

  6. pdf.js的使用(2)新的需求已经出现,怎么能够停止不前(迪迦奥特曼主题曲)哈哈哈。^_^

    来,咱们看图说事 按钮1,2是pdf.js自带的,分别对应顺时针旋转90度,逆时针旋转90度.于是乎又要我做一个旋转180度的按钮,诺!按钮3来了. 1.别怂,干!首先顺藤摸瓜,看按钮1,2的html ...

  7. web打开本地文件并读取内容

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. 【Hibernate 一对多】

    OneToMany public class OneToMany { @Test public void testAdd1() { SessionFactory sessionFactory = nu ...

  9. 基于Facebook开源框架SocketRocket的即时通讯

    SocketRocket 介绍: SocketRock 是 Facebook 开源的框架,基于 WebSocket 客户端类库,适用于 iOS.Mac OS.tv OS.GitHub 传送门:http ...

  10. 关于找不到指定的模块,异常来自HRESULT:0x8007007E的解决方法

    上午从公司前辈那里拷贝到的ASP.NET代码,在自己机器上部署的时候发现问题,直接报错,找不到指定的模块,异常来自HRESULT:0x8007007E.并且一大堆警告. 在网上百度很多解决方法,归纳如 ...