题目链接: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 实现点击菜单栏图标最小化程序

    compizconfig-settings-manager http://blog.csdn.net/wdjhzw/article/details/39136057

  2. Java入门第三季排序练习

    package imooc_collection_map_demo; import java.util.ArrayList;import java.util.Collections;import ja ...

  3. HostOnly模式下的Centos克隆虚拟机+配置固定ip

    首先在你想克隆的虚拟机上右击,选择管理下的克隆 让我们骚等一会~ ok,现在开机,这个时候是没有ip的 来修改一个文件 删掉红框中的内容,把箭头指的eth1改为eth0 在来修改一个文件 删掉红框的内 ...

  4. nyoj 79 拦截导弹 (动态规划)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=79 题意即求最长单调递减子序列 #include<iostream> #inc ...

  5. kworker

    通过 ps 命令查看进程状态时,可以查看到kworker相关, 大部分格式都是  kworker /u2:0 或者  kworker /0:0H, 查看资料得知: 内核中有很多kworker,有绑定c ...

  6. GIT 代码管理工具 SourceTree

    什么是git? git是一款开源的分布式版本控制工具 在世界上所有的分布式版本控制工具中,git是最快.最简单.最流行的 git的起源 作者是Linux之父:Linus Benedict Torval ...

  7. BIEE基本函数

    一,TRIM ,去除空字符 TRIM(EXPR) SUBSTRING("UT TIME"."月份" FROM 6 FOR 2) 1.AGGREGATE AT 此 ...

  8. springIOC

    从这段代码开始 ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); Pers ...

  9. 安卓平台 全面支持软解和硬解的SDK-Demo源代码开放

    专业做视频编解码的SDK开发工作. 2015年12月1日10:46:55: 更新到1.5.0版本 功能列表: 基本播放: 1,正常播放, 支持MP4,FLV,AVI,TS,3GP,RMVB,WM,WM ...

  10. emguCv3.x 实现字符分割,轮廓检测

    /// <summary> /// 获取区域 /// </summary> /// <param name="bitmap"></para ...