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 ...
随机推荐
- AutoLayout 之NSLayoutConstraint
这次主要讲的用代码来设置AutoLayout,为实现添加autoLayout视图主要介绍使用如下该方法,调用方法:- (void)awakeFromNib {} +(instancetype)cons ...
- 使用signalR创建聊天室。
浏览器支持Html5的情况下,SignalR使用WebSockets,当不支持时SignalR将使用其它技术来实现通讯. 界面如下:左侧包含三种聊天对象,不同的聊天对象会创建不同的对话框. 设计思路参 ...
- vultr新用户注册享受50美元优惠码,长期有效
vultr vps服务器,我用了三年多,购买了几十台vps,性价比非常高. 近期,vutlr推出了最新优惠码DOMORE长期有效,新用户注册账号时候,可在付款方式界面输入这个优惠码,享受50美元余额, ...
- springmvc框架下ajax请求传参数中文乱码解决
springmvc框架下jsp界面通过ajax请求后台数据,传递中文参数到后台显示乱码 解决方法:js代码 运用encodeURI处理两次 /* *掩码处理 */ function maskWord( ...
- centos7配置开启无线网卡,重启防火墙
centos7配置无线网卡: 在虚拟机为nat的网络连接下(就是默认的那个),centos7默认网卡未激活. 可以设置 文件 /etc/sysconfig/network-scripts/ifcfg- ...
- 获取XMLHttpRequest对象
//创建一个XMLHttpRequest对象 ,利用此对象与服务器进行通信 是AJAX技术的核心 /////////////////////////////////////////////////// ...
- Unity3D脚本使用:Time
1.Time 使用方式 使用效果 2.yield 延迟执行 嵌套延迟
- 使用pabot并发执行robotframework的testSuite
下载robotremoteserver-1.0.1.tar.gz.robotframework-pabot-0.22.tar.gz 执行以下命令,以安装pabot: pip install robot ...
- 一个简单sql注入的poc
最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块urllib,re. 功能:验证CmsEasy5.5爆账号密码 实验用源码:http://pan.baidu.co ...
- Java NIO Channel之FileChannel [ 转载 ]
Java NIO Channel之FileChannel [ 转载 ] @author zachary.guo 对于文件 I/O,最强大之处在于异步 I/O(asynchronous I/O),它允许 ...