CF1040A Palindrome Dance

RK3588内核崩溃日志捕获:pstore与ramoops的实战配置指南 本文详细介绍了在RK3588嵌入式设备上配置pstore与ramoops以捕获内核崩溃日志的实战指南。通过内核配置调整、设备树设置及高级调试技巧,帮助开发者有效定位系统崩溃原因,特别适合户外智能设备等无法长期连接调试器的场景。文章还提供了生产环境优化建议,确保日志捕获的可靠性与安全性。 阅读详情

原题链接:http://codeforces.com/contest/1040/problem/A

Palindrome Dance

A group of n n n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they’ve studied their dancing moves and can’t change positions. For some of them, a white dancing suit is already bought, for some of them — a black one, and for the rest the suit will be bought in the future.

On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer’s suit is the same as the color of the rightmost dancer’s suit, the 2nd left is the same as 2nd right, and so on.

The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it’s possible, what’s the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.

Input

The first line contains three integers n n n, a a a, and b ( 1 ≤ n ≤ 20 , 1 ≤ a , b ≤ 100 ) b (1≤n≤20, 1≤a,b≤100) b(1≤n≤20,1≤a,b≤100) — the number of dancers, the cost of a white suit, and the cost of a black suit.

The next line contains n n n numbers c i , i c_i, i ci​,i-th of which denotes the color of the suit of the i i i-th dancer. Number 0 0 0 denotes the white color, 1 1 1 — the black color, and 2 2 2 denotes that a suit for this dancer is still to be bought.

Output

If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.

Examples
input

5 100 1
0 1 2 1 2

output

101

input

3 10 12
1 2 0

output

-1

input

3 12 1
0 1 0

output

0

Note

In the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.

In the second sample, the leftmost dancer’s suit already differs from the rightmost dancer’s suit so there is no way to obtain the desired coloring.

In the third sample, all suits are already bought and their colors form a palindrome.

题解

因此题过水,题解被折叠。

代码
#include<bits/stdc++.h>
using namespace std;
const int M=25;
int n,a,b,ans,x1[M],x2[M];
void in(){scanf("%d%d%d",&n,&a,&b);for(int i=1;i<=n;++i)scanf("%d",&x1[i]),x2[n-i+1]=x1[i];}
void ac()
{
	for(int i=1;i<=n;++i)
	if(x1[i]==2)ans+=(x2[i]==2?min(a,b):(x2[i]?b:a));
	else if(x1[i]!=x2[i]&&x2[i]!=2)puts("-1"),exit(0);
	printf("%d",ans);
}
int main(){in();ac();}
【毫米波混合波束成形】第3章 深度展开网络:将迭代优化嵌入计算图 相位提取算子 $P_\phi: \mathbb{C}^N \to \mathbb{C}^N$ 定义为逐元素相位归一化 $P_\phi(z) = \exp(j \cdot \angle z)$。该算子在复数域非全纯(Non-holomorphic),标准反向传播需扩展至Wirtinger微积分框架。对于复数变量 $z = x + jy$,Wirtinger导数定义:相位提取算子的Jacobian矩阵在极坐标下具有稀疏结构。 阅读详情

相关推荐

【ESP32 S3 开发】基于I2S协议驱动INMP441数字麦克风 实现语音采集

注意INMP441的 L/R接地之后才稳定输出数据 否则一直都是0WAV格式说明这里主要是想说wav文件重要的就是生成一个wavhead来标识它是一个wave文件,wave文件的data chunk 中的data部分还是PCM编码格式的数据,直接从I2S读进去就可以,不需要压缩。wav文件的头一般由4个chunk组成。 以16bit深度为例,代码如下。其他深度可以根据注释自行计算。 I2S -> DAC i2s_read()函数,向flash中划分的一个buff当中读入byte数组。以16bit深度为例,一

m0_43395703的博客 1万+

codeforces 1040a (回文数的舞蹈)

原题链接 A. Palindrome Dance A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they’ve studied their dancing moves and can’t change positions. For...

starlet_kiss的博客 381

eQTL:连接突变与基因表达的桥梁

欢迎关注”生信修炼手册”!在高等生物中,很多的重要性状都为数量形状,比如农作物的产量,人类复杂疾病(高血液,糖尿病)等等。对于这些数量性状而言,往往受到多个基因的调控作用。为了更好的开展...

庐州月光的博客 7093

UVA Palindromes(模拟)

Palindromes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same for

叶孤心的专栏 747

即插即用!5分钟为你的SNN模型添加频谱注意力(DCT-SA模块实战)

本文介绍了如何为脉冲神经网络(SNN)快速集成即插即用的DCT-SA频谱注意力模块。该模块利用离散余弦变换(DCT)在频率域自适应加权特征,能有效提升模型对纹理、边缘的感知能力,并在CIFAR10-DVS等数据集上实现分类精度提升与脉冲发放率下降。文章以SpikingJelly框架和ResNet19为例,提供了详细的代码实现、集成步骤及参数调优实战指南。

kotlin6android的博客 612

Mac用户必看:PD虚拟机网络初始化失败的3分钟修复指南(附详细截图)

本文针对Mac用户在Parallels Desktop(PD虚拟机)启动时遇到的“网络初始化失败”问题,提供了快速诊断与修复指南。核心原因是macOS系统更新后权限未正确授予。文章通过详细的三步修复法(关闭进程、修改配置文件、重新授权重启),帮助用户在3分钟内恢复虚拟机网络连接,并附有排查清单与预防建议。

weixin_29231027的博客 550

Palindrome Dance

Palindrome Dance A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they’ve studied their dancing moves and can’t change positions. For some of them, a white dancing suit is already bought, for some of

Hello_wcrd的博客 206

大众奥迪诊断不求人:手把手解析SAE J2819(CAN TP2.0)协议报文与连接流程

本文深入解析大众奥迪车型诊断核心标准SAE J2819(CAN TP2.0)协议,详细拆解连接建立流程与报文控制字段。通过实战案例展示通道设置、参数协商等关键步骤,提供诊断设备配置建议和常见故障排查技巧,帮助工程师掌握汽车诊断通信协议的精髓。

weixin_30421809的博客 406

1040A Palindrome Dance

点击传送门查看题目:传送门 题意:有n个人,要每个穿西服,有三种情况,一种是穿了白色0西装, 一种是穿了黑色的1西装,还有一种没有穿用2表示, 现在需要给没有穿的人买西装,让他们颜色形成回文串,如果不可能形成就输出-1。 题解:模拟  两边向中间判断,如果是不相等,并且没有2,就输出-1,如果两个相等都为2,ans就加花费小的*2,如果相等不为2,就跳过,如果不想等,把2变成对面那个对应的颜...

memory_qianxiao的博客 551

EPLAN 电气制图(六):电机正反转副勾主电路绘制

【插入】→【设备】→选择 “SIE.3RV2011-1AA15”(Q1)和 “SIE.1TL0001-1DB3”(M1),放置于图纸左侧。生成端子排 X3:【端子排导航器】→新建编号 “1-20”,部件 “PXC.3211814”,放置于电机上方,功能文本标注 “电机端子”。属性设置:双击结构盒,在 “显示设备标识符” 中输入位置代号(如 “+ 柜外”),并在 “格式” 选项卡中调整线型与颜色。实用技巧:勾选【选项】→【设置】→【图形的编辑】中的 “绘制带有空白区域的结构盒”,可使元件布局更清晰。

电工 2049

【物联网】基于LORA组网的远程环境监测系统设计(ThingsCloud云平台版)_资料编号34

实现一主多从的LORA组网远程通信,主机和两个从机都配备了STM32F103单片机与 LoRa 模块,主机作为中心设备及WIFI网关,负责接收和发送数据到远程物联网平台和手机APP,两个从机则负责采集数据并通过各自的 LoRa组网将数据发送给主机。

嵌入式阿齐Archie 1万+

Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A. Palindrome Dance

problem link:http://codeforces.com/contest/1040/problem/A 题意:给你一个n和一个含有n个数字的数组,其中数组只包含0(白色已买0),1(黑色已买),2(未买);再给你两个值a,b分别代表买一套白色套装的费用和买一套黑色套装的费用。问为了使这个数组成为一个回文串,最少需要花费多少来购买服装。 解题报告: (1)由于n,a,b给的都很小。所...

Light2Chasers的博客 340

[Bug已解决] CUDA error 尽管 CUDA 可用且 GPU 受支持-通用排查 RuntimeError 解决方案

[Bug已解决] CUDA error 尽管 CUDA 可用且 GPU 受支持-通用排查 RuntimeError 解决方案

一键难忘的博客 2419

Codeforces1040A Palindrome Dance

CSDN失踪人口回归了,毕竟还是要准备SOI的,从今天开始重新写题解了 A. Palindrome Dance 题意 给出一串由0,1,2表示的数字,0和1分别表示不同的颜色,2表示无色,和两种变色的花费,现在使这串数字变为回文串,使得总花费最小 题解 从左到右,分几种情况讨论下就好了,分类讨论 code #include&amp;amp;amp;lt;iostream&amp;amp;amp;gt; #inc...

Welcome to yjjr's blog! 221

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

CF 2018.09.06 00:35 题解(补)

比赛题目链接:http://codeforces.com/contest/1040 A. Palindrome Dance A group of nn dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing...

小白 494

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

1136. A Delayed Palindrome (20) 大数模拟

1136. A Delayed Palindrome (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Consider a positive integer N written

zhangchaosd的博客 1204

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

动态规划——Poj 1159 Palindrome

1)   题目 Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 46005   Accepted: 15688 Description A palindrome is a symmetrical s

Vector 4683

【LeetCode】- Valid Palindrome(正确的回文)

[ 问题: ] Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 直译:给你一个字符串, 判定它是否是回文(只统计字母、数字,其他字符请忽略)。

技术人生 5484

A - Palindrome

Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, “Can you propose an efficient algorithm to find the length of the largest palindrome in a string?” A string is said to be a p

苦鬼·。 364

1136 A Delayed Palindrome (20分)

题目 Consider a positive integer NNN written in standard notation with k+1k+1k+1 digits aia_iai​ as ak⋯a1a0a_k⋯a_1 a_0ak​⋯a1​a0​ with 0≤ai<100\le a_i\lt100≤ai​<10 for all iii and ak>0a_k\gt0ak​...

小白的博客 244

LeetCode-9 Palindrome Number(判断是否为回文int型)

LeetCode-9 Palindrome Number Determine whether an integer is a palindrome. Do this without extra space.   方法一:直接转String倒置 public class Solution { public boolean isPalindrome(int x) {

你若嘻哈过盛,别人就不再欣赏你的认真 1223

2017中国大学生程序设计竞赛-哈尔滨站 A - Palindrome

Palindrome Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 426Accepted Submission(s): 163 Problem Description Alice like strings, esp...

weixin_33849215的博客 194

CF- 798A. Mike and palindrome - 思维

1.题目描述: A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a st

终有绿洲摇曳在沙漠 1067

Palindrome (再加多少个字符才能成为回文串 dp)

A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal numb...

自渡的博客 437

A-B Palindrome(回文串 暴力模拟)

You are given a string s consisting of the characters ‘0’, ‘1’, and ‘?’. You need to replace all the characters with ‘?’ in the string s by ‘0’ or ‘1’ so that the string becomes a palindrome and has exactly a characters ‘0’ and exactly b characters ‘1’. No

Lily的博客 414

981A Antipalindrome

A. Antipalindrometime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is a palindrome if it reads the same from the left to the right and from ...

memory_qianxiao的博客 1028
上一篇: CF1042F Leaf Sets
下一篇: CF1040B Shashlik Cooking
ShadyPi
博客等级 码龄9年 1万+粉丝 637原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值