题目链接:Codeforces Round #367 (Div. 2) C. Hard problem

题意:

给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字符串排成字典序

题解:

当时1点过头太晕了,看错题了,然后感觉全世界都会,就我不会,- -!结果就是一个简单的DP,

设dp[i][0]表示第i个字符串不反转的情况,dp[i][1]表示第i个字符串反转的情况

状态转移方程看代码

 #include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll; const int N=1e5+;
ll dp[N][],inf=(1ll<<)-;
int n,v[N],lena,lenb;
char a[N],b[N],c[N],d[N]; inline void up(ll &a,ll b){if(a>b)a=b;} int main()
{
scanf("%d",&n);
F(i,,n)scanf("%d",v+i);
scanf("%s",a),lena=strlen(a);
for(int i=,j=lena-;i<lena;i++,j--)c[j]=a[i];
dp[][]=,dp[][]=v[],c[lena]='\0';
F(i,,n)
{
scanf("%s",b),lenb=strlen(b),d[lenb]='\0';
for(int ii=,j=lenb-;ii<lenb;ii++,j--)d[j]=b[ii];
dp[i][]=dp[i][]=inf;
if(strcmp(a,b)<=)up(dp[i][],dp[i-][]);
if(strcmp(c,b)<=)up(dp[i][],dp[i-][]);
if(strcmp(a,d)<=)up(dp[i][],dp[i-][]+v[i]);
if(strcmp(c,d)<=)up(dp[i][],dp[i-][]+v[i]);
strcpy(a,b),strcpy(c,d),lena=lenb;
}
ll ans=min(dp[n][],dp[n][]);
printf("%I64d\n",ans==inf?-:ans);
return ;
}

Codeforces Round #367 (Div. 2) C. Hard problem的更多相关文章

  1. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  2. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)

    Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...

  3. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  4. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  5. Codeforces Round #367 (Div. 2) (A,B,C,D,E)

    Codeforces Round 367 Div. 2 点击打开链接 A. Beru-taxi (1s, 256MB) 题目大意:在平面上 \(n\) 个点 \((x_i,y_i)\) 上有出租车,每 ...

  6. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset

    题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 ...

  7. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  8. Codeforces Round #367 (Div. 2) Hard problem

    Hard problem 题意: 有n个字符串,对第i个字符串进行反转操作代价为ci. 要使n个字符串按照字典序从小到大排列,最小的代价是多少. 题解: 反转就是reverse操作,比如说45873反 ...

  9. 「专题训练」Hard problem(Codeforces Round #367 Div. 2 C)

    题意与分析 题意:给出\(n\)个字符串,可以反转任意串,反转每个串都有其对应的花费\(c_i\).经过操作后是否能满足字符串\(\forall i \in [1,n] \text{且} i \in ...

随机推荐

  1. Ubuntu 16 04 安装KVM

    apt-get install qemu-kvm ubuntu-vm-builder bridge-utils http://www.linuxidc.com/Linux/2016-06/132188 ...

  2. TypeUtils -- Object 转为 强类型

    public static class TypeUtils { /// <summary> /// Object 转为 强类型 /// </summary> public st ...

  3. [转]学好Mac常用命令,助力iOS开发

    转自:http://www.jianshu.com/p/d9ec00d28237   序言 在iOS开发的过程中,更多地注重iOS开发的效率,熟练使用Mac终端操作的常用命令,可以让你更好的游刃于iO ...

  4. VS生成桌面应用程序

    1.简介 1/ 什么是WPF WPF,Windows Presentation Foundation也,译过来就是"Windows呈现基础",你看它的目的非常明确,就是用来把数据& ...

  5. C#函数以及应用

  6. 【1】ShopNC 模仿笔记(一)

    不断学习,人生将会成功. 1. 序 一直想模仿一个整套的商城, 今天在shopNC 里面看到了想要的一切, 所以把一些组件, 命名规范等记录下来, 提高以后的开发效率. 官方网站 PC : shopN ...

  7. c#语言简介

    语言的历史:c,c++,java,c#, c语言最早,c++语言复杂,而java把其中难的一部分去掉,也成为c--,而c#早期类似java. c#简单高效,并且与web结合. C#的运行环境是.net ...

  8. 安装器---Inno Setup

    Inno Setup[1]  用Delphi写成,其官方网站同时也提供源程序免费下载.它虽不能与Installshield这类恐龙级的安装制作软件相比,但也当之无愧算是后起之秀.Inno Setup是 ...

  9. [帖子收集]环境光遮蔽(Ambient Occlusion)

    环境光遮蔽,效果示例图 图片左边是一条龙的简单模型,呈现在一个均匀照明的环境中.尽管模型中有一些明暗不同的区域,但大部分光照都是均匀的.虽然模型有着相当复杂的几何形状,但看上去比较光滑平坦,没有明显的 ...

  10. Framebuffer原理、使用、测试系列文章,非常好的资料,大家一起学习

    转载:http://blog.csdn.net/tju355/article/details/6881372 *一.FrameBuffer的原理* FrameBuffer 是出现在 2.2.xx 内核 ...