题目链接:https://codeforces.com/problemset/problem/706/C

题意:

给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整个翻转。

要你尽量用最少的花费,使得 $n$ 个字符串按照字典序升序排序。

题解:

$f[i][0,1]$ 表示前 $i$ 个字符串,第 $i$ 个不翻转(或者翻转)的情况下,最少的花费。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e5+;
int n;
string s[maxn][];
ll c[maxn],f[maxn][];
int main()
{
ios::sync_with_stdio();
cin.tie(), cout.tie(); cin>>n;
for(int i=;i<=n;i++) cin>>c[i];
for(int i=;i<=n;i++)
{
cin>>s[i][];
s[i][]=s[i][];
reverse(s[i][].begin(),s[i][].end());
} memset(f,INF,sizeof(f));
f[][]=, f[][]=c[];
for(int i=;i<=n;i++)
{
if(s[i][]>=s[i-][]) f[i][]=min(f[i][],f[i-][]);
if(s[i][]>=s[i-][]) f[i][]=min(f[i][],f[i-][]);
if(s[i][]>=s[i-][]) f[i][]=min(f[i][],f[i-][]+c[i]);
if(s[i][]>=s[i-][]) f[i][]=min(f[i][],f[i-][]+c[i]); if(f[i][]>=INF && f[i][]>=INF) break;
} ll ans=min(f[n][],f[n][]);
cout<<((ans>=INF)?-:ans)<<endl;
}

Codeforces 706C - Hard problem - [DP]的更多相关文章

  1. Codeforces 1096D - Easy Problem - [DP]

    题目链接:http://codeforces.com/problemset/problem/1096/D 题意: 给出一个小写字母组成的字符串,如果该字符串的某个子序列为 $hard$,就代表这个字符 ...

  2. CodeForces 706C Hard problem (水DP)

    题意:对于给定的n个字符串,可以花费a[i]  将其倒序,问是否可以将其排成从大到小的字典序,且花费最小是多少. 析:很明显的水DP,如果不是水DP,我也不会做.... 这个就要二维,d[2][max ...

  3. CodeForces - 706C Hard problem(dp+字符串)

    题意:有n个字符串,只能将其逆转,不能交换位置,且已知逆转某字符串需要消耗的能量,问将这n个字符串按字典序从小到大排序所需消耗的最少能量. 分析:每个字符串要么逆转,要么不逆转,相邻两个字符串进行比较 ...

  4. 【动态规划】Codeforces 706C Hard problem

    题目链接: http://codeforces.com/contest/706/problem/C 题目大意: n(2 ≤ n ≤ 100 000)个字符串(长度不超过100000),翻转费用为Ci( ...

  5. Codeforces 706C Hard problem 2016-09-28 19:47 90人阅读 评论(0) 收藏

    C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. CodeForces 706C Hard problem

    简单$dp$. $dp[i][0]$:第$i$个串放置完毕,并且第$i$个串不反转,前$i$个串字典序呈非递减的状态下的最小费用. $dp[i][1]$:第$i$个串放置完毕,并且第$i$个串反转,前 ...

  7. Codeforces 706 C. Hard problem (dp)

    题目链接:http://codeforces.com/problemset/problem/706/C 给你n个字符串,可以反转任意一个字符串,反转每个字符串都有其对应的花费ci. 经过操作后是否能满 ...

  8. CodeForces 176B Word Cut dp

    Word Cut 题目连接: http://codeforces.com/problemset/problem/176/C Description Let's consider one interes ...

  9. codeforces 148D之概率DP

    http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory l ...

随机推荐

  1. 【C#】解析C#中管道流的使用

    目录结构: contents structure [+] 匿名管道(anonymous pipe) 命名管道(named pipe) 管道为进程间通信提供了一种可能.管道分为两种,一种是匿名管道,另一 ...

  2. Open Graph Protocol(开放内容协议)

    最近在整理公司hexo博客的时候突然发现在页面 head 里面有一个这个奇怪的 meta Open Graph Protocol(开放内容协议) 开放内容协议一种新的HTTP头部标记,即这种协议可以让 ...

  3. 如何保证修改resolv.conf后重启不恢复?

    如何保证修改resolv.conf后重启不恢复? 修改/etc/resolv.conf,重启网卡后,/etc/resolv.conf恢复到原来的状态. CentOS.redhat下面直接修改/etc/ ...

  4. 文档大师 在Win10 IE11下,文档集画面无法正常显示Word等Office文档的解决方法

    在文档集界面中显示Word文档,是文档大师的一个核心功能. 最近在 Win10 升级到最新版后,发现 无法正常显示Office 文档的问题. 一开始以为是Word版本问题,从2007升级到2016,问 ...

  5. css实现高度或者宽度不固定的div元素垂直左右居中

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. C语言 · FBI树

    算法训练 FBI树   时间限制:1.0s   内存限制:256.0MB        锦囊1 二叉树. 问题描述 我们可以把由“0”和“1”组成的字符串分为三类:全“0”串称为B串,全“1”串称为I ...

  7. SpringMvc支持跨域访问,Spring跨域访问,SpringMvc @CrossOrigin 跨域[转]

    SpringMvc支持跨域访问,Spring跨域访问,SpringMvc @CrossOrigin 跨域 原文地址:https://www.cnblogs.com/fanshuyao/p/716847 ...

  8. 看雪CTF第十题

    __int64 sub_140006F50() { __int64 v0; // r8@1 __int64 v1; // r9@1 signed __int64 len; // rax@1 __int ...

  9. python3 写一个简单的websocket程序(转)

    原贴:https://segmentfault.com/q/1010000009284816?_ea=1883181 也是找了好久 #! /usr/bin/env python # -*- codin ...

  10. 【ORACLE】解锁scott帐号

    sqlplus / as sysdba;SQL> alter user scott account unlock;SQL> conn scott/grace