Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) APalindrome Dance
Posted awcxv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) APalindrome Dance相关的知识,希望对你有一定的参考价值。
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
i从1..n/2循环一波。
保证a[i]和a[n-i+1]就好。
如果都是2的话填上min(a,b)*2就好
其他情况跟随非2的。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 20;
int n,a,b,cost[2];
int c[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
scanf("%d%d%d",&n,&a,&b);
cost[0] = a,cost[1] = b;
rep1(i,1,n) scanf("%d",&c[i]);
int ans = 0;
rep1(i,1,n/2){
int l = i,r = n-i+1;
if (c[l]==2 && c[r]==2){
ans+=min(a,b)*2;
}else{
if (c[l]==2){
ans+=cost[c[r]];
}else if (c[r]==2){
ans+=cost[c[l]];
}else if (c[l]!=c[r]){
cout<<-1<<endl;
return 0;
}
}
}
if (n&1){
if (c[n/2+1]==2){
ans+=min(a,b);
}
}
printf("%d
",ans);
return 0;
}
以上是关于Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) APalindrome Dance的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)
Educational Codeforces Round 83 (Rated for Div. 2)E(区间DP)
Codeforces Round #436 E. Fire(背包dp+输出路径)
[ACM]Codeforces Round #534 (Div. 2)