Codeforces Round #367 (Div. 2) C. Hard problem
来源:互联网 发布:监测数据造假怎么举报 编辑:程序博客网 时间:2024/06/06 18:22
http://codeforces.com/contest/706/problem/C
#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;const int maxn = 100010;int c[maxn];string s[maxn];string rs[maxn];long long dp[maxn][2];int main(){ int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &c[i]); for (int i = 1; i <= n; i++) { cin >> s[i]; rs[i] = s[i]; reverse(rs[i].begin(), rs[i].end()); } s[0] = rs[0] = ""; memset(dp, 0x3f, sizeof(dp)); dp[0][0] = dp[0][1] = 0; for (int i = 1; i <= n; i++) { if (s[i] >= s[i - 1]) dp[i][0] = min(dp[i][0], dp[i - 1][0]); if (rs[i] >= s[i - 1]) dp[i][1] = min(dp[i][1], c[i] + dp[i - 1][0]); if (s[i] >= rs[i - 1]) dp[i][0] = min(dp[i][0], dp[i - 1][1]); if (rs[i] >= rs[i - 1]) dp[i][1] = min(dp[i][1], c[i] + dp[i - 1][1]); } long long ans = min(dp[n][0], dp[n][1]); if (ans > 1e15) cout << "-1" << endl; else cout << ans << endl; return 0;}
0 0
- Codeforces Round #367 (Div. 2)-C - Hard problem-DP
- 【Codeforces Round 367 (Div 2) C】【简单DP】Hard problem
- Codeforces Round #367 (Div. 2) C. Hard problem (DP)
- Codeforces Round #367 (Div. 2) C. Hard problem (dp)
- Codeforces Round #367 (Div. 2) C. Hard problem
- Codeforces Round #367 (Div. 2) C. Hard problem
- Codeforces Round #367 (Div. 2) C Hard problem(DP)
- Codeforces Round #367 (Div. 2)C. Hard problem
- Codeforces Round #367 (Div. 2) C. Hard problem (dp)
- Codeforces Round #367 (Div. 2) C. Hard problem(dp)
- Codeforces Round #367 (Div. 2) [C] Hard Problem
- Codeforces Round #367 (Div. 2) C. Hard problem
- Codeforces Round #367 (Div. 2) C. Hard problem (DP)
- Codeforces Round #367 (Div. 2) C Hard problem(dp)
- Codeforces Round #361 (Div. 2) C.NP-Hard Problem
- Codeforces Round #360 (Div. 2) C. NP-Hard Problem
- Codeforces Round #360 (Div. 2) C. NP-Hard Problem
- Codeforces Round #367 (Div. 2)Hard problem DP
- 2016多校8th 1008【线段树-神题】
- cornerstone分支简单使用(三)
- CSS3动画(个人理解)
- 分数类(雏形)
- eclipse智能提示与常用快捷键
- Codeforces Round #367 (Div. 2) C. Hard problem
- Memcache 缓存
- Python函数可变参数* args及**kwargs 应用
- 一个简单的tomcat应用(HFSJ)
- Doxygen使用学习(一)------Doxygen的简单注释格式
- jQuery性能优化建议
- group by与distinct效率分析及优化措施
- 百度查到网页违规代码修改好后竞价账户一直审核不通过,怎么办?
- Linux数据流重定向