CF Round #367 C题
题目 链接:http://codeforces.com/contest/706/problem/C
好像又是DP...
dp[i][0]表示第i个字符串不翻转成字典序排列的花费,dp[i][1]表示第i个字符串翻转成字典序排列的花费;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=2e6+,inf=1e9+;
const ll INF=1e17;
ll dp[N][];
string str1[N];
string str2[N];
ll a[N];
void init()
{
for(int i=;i<N;i++)
dp[i][]=dp[i][]=INF;
}
int main()
{
int x,y,z,i,t;
init();
scanf("%d",&x);
for(i=;i<=x;i++)
scanf("%I64d",&a[i]);
for(i=;i<=x;i++)
{
cin>>str1[i];
str2[i]=str1[i];
reverse(str2[i].begin(),str2[i].end());
}
dp[][]=;
dp[][]=a[];
for(i=;i<=x;i++)
{
if(str1[i]>=str1[i-])
dp[i][]=min(dp[i][],dp[i-][]);
if(str1[i]>=str2[i-])
dp[i][]=min(dp[i][],dp[i-][]);
if(str2[i]>=str1[i-])
dp[i][]=min(dp[i][],dp[i-][]+a[i]);
if(str2[i]>=str2[i-])
dp[i][]=min(dp[i][],dp[i-][]+a[i]);
}
ll ans=min(dp[x][],dp[x][]);
if(ans<INF)
printf("%I64d\n",ans);
else
printf("-1\n");
return ;
}
CF Round #367 C题的更多相关文章
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #367 (Div. 2) C. Hard problem
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...
- CF Round #510 (Div. 2)
前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...
- 竞赛题解 - CF Round #524 Div.2
CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...
- 【前行&赛时总结】◇第4站&赛时9◇ CF Round 513 Div1+Div2
◇第4站&赛时9◇ CF Round 513 Div1+Div2 第一次在CF里涨Rating QWQ 深感不易……作blog以记之 ( ̄▽ ̄)" +Codeforces 的门为你打 ...
- CF Round #580(div2)题解报告
CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...
- 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 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
随机推荐
- java url encoder 的一个问题
@RequestMapping(value = {"/search"}) public String errorPath(HttpServletResponse response, ...
- C#网络编程——IPHostEntry
using System; using System.Net; namespace study { class IPHostEntrySample { public static void func( ...
- maven webapp栽坑录
一.需求 如何将一个java web项目传给别人?放到github上.要想放到github上,就要学会git,markdown和maven.像那些jar包是不鼓励传到github上的,应该尽量把源文件 ...
- charing animation
FHD : full high definition,1920 x 1080,全高清 vendor/mediatek/proprietary/bootable/bootloader/lk/dev/lo ...
- 滤镜 filter:gray 变灰色
.gray { -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); ...
- js中的json对象和字符串之间的转化
字符串转对象(strJSON代表json字符串) var obj = eval(strJSON); var obj = strJSON.parseJSON(); var obj = JSO ...
- neo4j-备份、恢复
neo4j备份命令(本例linux) neo4j-backup 命令使用: ./neo4j-backup -full -from single://[machine IP] -to ~/backup- ...
- 锋利的jquery-读书笔记(一)
最近转职做前端,学了两个月目前学到jquery的部分,看的是<锋利的jquery>这本书,特地开了博客将自己学习过程中看到的一些知识做一个笔记. 第一章: 一.jQuery对象和DOM对象 ...
- Leetcode 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- JavaScript工具代码
html编码 function htmlEscape(sHtml){ return sHtml && sHtml.replace(/[<>&"]/g, f ...