Codeforces Round #367 (Div. 2) C. Hard problem
题目链接: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的更多相关文章
- 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) 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) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- 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) (A,B,C,D,E)
Codeforces Round 367 Div. 2 点击打开链接 A. Beru-taxi (1s, 256MB) 题目大意:在平面上 \(n\) 个点 \((x_i,y_i)\) 上有出租车,每 ...
- Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset
题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 ...
- 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 ...
- Codeforces Round #367 (Div. 2) Hard problem
Hard problem 题意: 有n个字符串,对第i个字符串进行反转操作代价为ci. 要使n个字符串按照字典序从小到大排列,最小的代价是多少. 题解: 反转就是reverse操作,比如说45873反 ...
- 「专题训练」Hard problem(Codeforces Round #367 Div. 2 C)
题意与分析 题意:给出\(n\)个字符串,可以反转任意串,反转每个串都有其对应的花费\(c_i\).经过操作后是否能满足字符串\(\forall i \in [1,n] \text{且} i \in ...
随机推荐
- 石头剪刀布 OpenJudge 1.6.08
石头剪刀布是常见的猜拳游戏.石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负. 一天,小A和小B正好在玩石头剪刀布.已知他们的出拳都是有周期性规律的,比如:"石头-布-石头-剪 ...
- Oracle常用查询
-- 创建Oracle sequence create sequence SEQ_XXHF minvalue 1 maxvalue 9999999999999999999999999999 start ...
- Tip of the Day
Did you know ... ? You can view all statements within the method where certain exceptions can be cau ...
- 通过file文件选择图片预览功能
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 跨线程传递栈变量带来异常指针Crash
在手Q动漫的一份古老的代码中,现网发现少数crash,错误代码示例: char str[100] = "hello"; dispatch_async(dispatch_get_ma ...
- Minicom配置及使用详解
因为现在电脑基本不配备串行接口,所以,usb转串口成为硬件调试时的必然选择.目前知道的,PL2303的驱动是有的,在dev下的名称是ttyUSB*. minicom,tkterm都是linux下应用比 ...
- python 基础篇第一篇
本节内容 1.python介绍 2.发展史 3.python2和python3 4.安装 5.简单程序,hello world程序 6.变量 7.用户输入 8.模块初识 9..pyc是什么? 10.数 ...
- <hdu-2032>杨辉三角
这是杭电hdu上杨辉三角的链接:http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description: 还记得中学时候学过的杨辉三角吗 ...
- 杭州蓝松科技推出的安卓端的USB转串口调试助手, 欢迎下载使用
杭州蓝松科技推出的安卓端的USB转串口调试助手, 欢迎下载使用 下载地址:http://files.cnblogs.com/guobaPlayer/%E8%93%9D%E6%9D%BEUSB%E4%B ...
- Java多线程和死锁
一 .多线程: 售票窗口简单实例: public class SaleTicket { public static class Sale implements Runnable{ ; // @Over ...