Codeforces Gym 100733H Designation in the Mafia flyod
Designation in the Mafia
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88994#problem/H
Description
The Shitalian mafia has a very peculiar way to name a new associate. The newbie goes through tests to measure his strength, agility, sagacity and influence. The size of the nickname is defined by the results of the tests.
Then, the newbie chooses the characters of his nickname, that is, letters from the alphabet. But Shi has nothing better to do, so he demands that the nickname is transformed in a palindrome.
A palindrome is a string that can be read the same way if we reverse it. For instance BANANAB is a palindrome, and BANANAS is not.
Everything in Shitalia has a cost, including transforming characters. You will receive a matrix P, of size 26x26. The element Pij is the cost of transforming the i-th letter of the alphabet into the j-th letter of the alphabet. You can apply as many transformations as you want.
Find the minimum cost to transform the nickname into a palindrome.
Input
The first 26 lines form the matrix P. Each line i contains exactly 26 integers Pij(0 ≤ Pij ≤ 106), indicating . The last line contains the nickname that the newbie has chosen, which is a string with n(1 ≤ n ≤ 106) lowercase letters.
Output
Print the minimal cost to transform the nickname into a palindrome.
Sample Input
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
xx
Sample Output
0
HINT
题意
给你每一个字符变成另外一个字符的花费
然后问你最小需要多少才能把这个字符串变成回文串
题解:
看懂第三个样例,基本这道题就出来了
注意要跑flyod,这个cost[x][y]不一定比cost[x][k]+cost[k][y]低
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** long long cost[][];
int main()
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
cin>>cost[i][j];
}
cost[i][i]=;
}
for(int k=;k<;k++)
{
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
}
}
}
string s;
cin>>s;
ll ans=;
int len = s.size(); for(int i=;i<len/;i++)
{
ll mins = inf;
int i1 = s[i]-'a';
int i2 = s[len-i-] - 'a';
for(int j=;j<;j++)
mins = min(mins,cost[i1][j]+cost[i2][j]);
ans+=mins;
}
cout<<ans<<endl;
}
Codeforces Gym 100733H Designation in the Mafia flyod的更多相关文章
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
- codeforces Gym 100187J J. Deck Shuffling dfs
J. Deck Shuffling Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
随机推荐
- Spring AOP (上)
工作忙,时间紧,不过事情再多,学习是必须的.记得以前的部门老大说过:“开发人员不可能一天到晚只有工作,肯定是需要自我学习.第一:为了更充实自己,保持进步状态.第二:为了提升技术,提高开发能力.第三:保 ...
- 保护眼睛,开启浏览器的夜间模式 顺便学下!important的作用
打开笔记本程序,复制以下代码 *{background-image: none !important; background: none !important; background:#333333 ...
- Permutations java实现
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- 纯css实现扁平化360卫士logo demo
前几天在w3ctech上看到有人用纯css写出了360卫士的logo,感觉蛮好玩的. 因为自己用css以来,还没有写过这种玩意,出于娱乐,我也来试着尝试一下. 开始也不知到怎么下手,最棘手的是那两个像 ...
- Web服务器(Apache)虚拟主机的配置
一.定义 所谓虚拟主机是指在一台服务器里运行几个网站,提供WEB.FTP.Mail等服务. 二.虚拟主机的实现方法有三种: 基于IP的方法,基于主机名的方法和基于端口的法官法. ...
- PHP实现分页:文本分页和数字分页
来源:http://www.ido321.com/1086.html 最近,在项目中要用到分页.分页功能是经常使用的一个功能,所以,对其以函数形式进行了封装. // 分页分装 /** * $pageT ...
- java 复习001
java 复习001 比较随意的记录下我的java复习笔记 ArrayList 内存扩展方法 分配一片更大的内存空间,复制原有的数据到新的内存中,让引用指向新的内存地址 ArrayList在内存不够时 ...
- fedora20安装spin以及用户界面ispin
(博客园-番茄酱原创) (最近感觉用make会出现库错误,所以改进了教程,把之前的make步骤省掉了,直接下载可执行文件进行配置最简单啦...) 1.首先,下载对应版本的spin,我64位的fedor ...
- Apache Spark GraphX的体系结构
1. 整体架构 GraphX 的整体架构(如图 1所示)可以分为三部分. 图 1 GraphX 架构 存储和原语层: Graph 类是图计算的核心类.内部含有 VertexRDD. EdgeRDD ...
- homework09-虐心的现程设终于要告一段落了
V3.0版本今天凌晨出炉 添加了随机生成 添加了文件打开 完全按照老师的要求搞定了 V2.0版本更新 添加了中间数组变量显示 这次作业写了整整一天,把以前能用的代码都改了一个遍 最后变成了网页版的小程 ...