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. Python 命令行参数的输入方式(使用pycharm)

    形式一: 第一个红色框为命令行参数 第二个框为控制台模式(Terminal) 形式二 点击运行:点击红色框  编辑配置 如下图:红色框即为设置的命令行参数

  2. UVA - 13024 Saint John Festival 凸包+二分

    题目链接:https://vjudge.net/problem/UVA-13024 题意:先给出\(L\)个点构造一个凸包,再给出\(S\)个点,询问有几个点在凸包内. 题解:判断点是否在凸包内的模板 ...

  3. centos 6.5 升级到 python2.7

    准备 centos6.5的python版本默认是2.6.6,可能有的时候我们需要升级到更高的版本,那就来动手升级下吧.我这里以2.7.8版本为例,根据实际需要选择升级版本即可. yum install ...

  4. unittest---unittest错误截图

    在做自动化的过程中,大多数执行者都不在旁边,那么如果用例失败了我们通常看报告上的失败信息,但是这样有时候可能不够清楚的判断到底哪里出了错误,我们还可以通过自动截图的功能,判断用例走到哪里出了错误. 截 ...

  5. Java面向对象简单知识总结-考试用

    类.对象.构造器 类定义了属性.方法,是抽象的,写在扩展名为java的文件中. 对象是类的实体,是具体的. 构造器:方法名与类名一致.没有返回类型,可以重载不能重写.在创建对象时调用.使用new调用实 ...

  6. Wireshark 查看指定进程的网络包

    Wireshark 查看指定进程的网络包 打开任务管理器,右键筛选列,选中PID(进程标识符): 找到该进程对应的PID,如1200: 在cmd中执行netstat -ano|findstr 1200 ...

  7. iOS 开发中常用的排序(冒泡、选择、快速、插入、希尔、归并、基数)算法

    1.冒泡排序: 冒泡算法是一种基础的排序算法,这种算法会重复的比较数组中相邻的两个元素.如果一个元素比另一个元素大(小),那么就交换这两个元素的位置.重复这一比较直至最后一个元素.这一比较会重复n-1 ...

  8. 获取Linux系统运行情况信息

    代码: #include <stdio.h> #include <unistd.h> /* usleep() */ #include <stdlib.h> #inc ...

  9. Centos10卸载nginx

    1.停止服务 /usr/local/nginx/sbin/nginx -s stop yum remove nginx 2.查看Nginx相关文件 whereis nginx 删除:rm -rf /u ...

  10. MySQL高级-索引1

    1.索引是什么 索引(Index)是帮助MySQL高效获取数据的数据结构.可以得到索引的本质:索引是数据结构. 可以理解为“排好序的快速查找数据结构” 在数据之外,数据库系统还维护着满足特定查找算法的 ...