题目链接:http://codeforces.com/contest/706/problem/C

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+3;
const ll INF=1e18;
ll dp[N][2];
string a[N],b[N];
int c[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",c+i);
for(int i=0;i<n;i++)
{
cin>>a[i];
b[i]=a[i];
reverse(b[i].begin(),b[i].end());
}
for(int i=1;i<n;i++)
dp[i][0]=dp[i][1]=INF;
dp[0][1]=c[0];
int i;
for(i=1;i<n;i++)
{
if(a[i]>=a[i-1])
dp[i][0]=dp[i-1][0];
if(b[i]>=a[i-1])
dp[i][1]=dp[i-1][0]+c[i];
if(a[i]>=b[i-1])
dp[i][0]=min(dp[i][0],dp[i-1][1]);
if(b[i]>=b[i-1])
dp[i][1]=min(dp[i][1],dp[i-1][1]+c[i]);
if(dp[i][0]==INF&&dp[i][1]==INF)
break;
}
if(i==n)
printf("%I64d\n",min(dp[n-1][0],dp[n-1][1]));
else
printf("-1\n");
return 0;
}

codeforces round367 div2.C (DP)的更多相关文章

  1. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  2. codeforces 369 div2 C dp

    http://codeforces.com/contest/711 C. Coloring Trees time limit per test 2 seconds memory limit per t ...

  3. CodeForces #363 div2 Vacations DP

    题目链接:C. Vacations 题意:现在有n天的假期,对于第i天有四种情况: 0  gym没开,contest没开 1  gym没开,contest开了 2 gym开了,contest没开 3 ...

  4. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  5. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  6. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  7. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  8. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  9. [Codeforces 1201D]Treasure Hunting(DP)

    [Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...

随机推荐

  1. PHP基本知识收集

    1.符号“@”的作用 @是可以屏蔽函数执行过程中遇到问题而产生的一些错误.警告信息,这样用户就看不到程序的出错信息.这样除了用户界面会友好一些外,更重要的是安全性,因为屏蔽了出错文件的路径等信息. 2 ...

  2. git 将本地项目添加到远程

    git init git add README.md git commit -m "first commit" git remote add origin git@github.c ...

  3. Octopus系列之接下来的任务

    更新默认国家[已实现] 更新每页显示条数的后台控制[已实现] 更新国家和区域的Ajax的关联[已实现] 更新详情页面的 属性选择 脚本提示[已实现 可以做到和兰亭一样的效果了] 增加优惠方案的设置和批 ...

  4. PHP多线程类

    <?php /** * @title: PHP多线程类(Thread) * @version: 1.0 * @author: phper.org.cn < web@phper.org.cn ...

  5. java 面向对象编程-- 第15章 集合框架

    1.  集合特点:元素类型不同.集合长度可变.空间不固定 2.  java中对一些数据结构和算法进行了封装即集合.集合也是一种对象,用于存储.检索.操作和传输对象. 3.  JCF(Java Coll ...

  6. LinearLayout练习

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  7. (转载)全球唯一标识GUID

    GUID(Global unique identifier)全局唯一标识符,它是由网卡上的标识数字(每个网卡都有唯一的标识号)以及 CPU 时钟的唯一数字生成的的一个 16 字节的二进制值. GUID ...

  8. PowerMock.expectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments)

    1:PowerMock.expectNew(Class<T> type, Class<?>[] parameterTypes, Object... arguments) 如果你 ...

  9. myeclipse中导入的jquery文件报错(出现红叉叉,提示语法错误)

    转自:http://blog.csdn.net/simplty/article/details/7661504

  10. [Windows驱动]流媒体驱动开发

    从Windows98开始,Windows流媒体驱动遵循Windows Driver Model(WDM)模型并使用Kernel Streaming(KS)组件.Kernel Streaming(KS) ...