hdu 1546 Idiomatic Phrases Game
http://acm.hdu.edu.cn/showproblem.php?pid=1546
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#define maxn 1001
using namespace std;
const int inf=<<; int a[maxn],n;
int g[maxn][maxn];
char str[maxn][maxn];
int dis[maxn];
bool vis[maxn]; void spfa()
{
queue<int>q;
memset(vis,false,sizeof(vis));
for(int i=; i<=n; i++) dis[i]=inf;
dis[]=;
vis[]=true;
q.push();
while(!q.empty())
{
int u=q.front(); q.pop();
vis[u]=false;
for(int i=; i<n; i++)
{
if(g[u][i]!=inf&&dis[i]>dis[u]+g[u][i])
{
dis[i]=dis[u]+g[u][i];
if(!vis[i])
{
q.push(i);
vis[i]=true;
}
}
}
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
for(int i=; i<n; i++)
{
cin>>a[i]>>str[i];
}
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
if(i==j) g[i][j]=;
else g[i][j]=inf;
}
}
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
if(i==j) continue;
bool flag=false;
int k=strlen(str[i]);
for(int c=; c<; c++)
{
if(str[i][k+c-]!=str[j][c])
{
flag=true;
break;
}
}
if(!flag)
{
g[i][j]=a[i];
}
}
}
/*for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
printf("%d ",g[i][j]);
}
printf("\n");
}*/
spfa();
if(dis[n-]==inf) printf("-1\n");
else printf("%d\n",dis[n-]);
}
return ;
}
hdu 1546 Idiomatic Phrases Game的更多相关文章
- HDU 1546 Idiomatic Phrases Game 求助!help!!!
Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- HDU 1546 Idiomatic Phrases Game(最短路,Dijsktra,理解题意很重要)
题目 1.注意因为要判断能不能到达,所以要在模版里面判断k有没有更新. 2.看懂题目意思和案例的解法很重要. #define _CRT_SECURE_NO_WARNINGS //题目大意:现要进行单词 ...
- HDU - 1546 ZOJ - 2750 Idiomatic Phrases Game 成语接龙SPFA+map
Idiomatic Phrases Game Tom is playing a game called Idiomatic Phrases Game. An idiom consists of sev ...
- hdu 1546(dijkstra)
Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- Idiomatic Phrases Game(图论最短路)
Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- Idiomatic Phrases Game(最短路+注意坑点)
Tom is playing a game called Idiomatic Phrases Game. An idiom consists of several Chinese characters ...
- ZOJ 2750 Idiomatic Phrases Game(Dijkstra)
点我看题目 题意 : 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程就是成语接龙,后一个成语的第一个字必须有前一个成语的最后一个字相等,给定的 ...
- zoj 2750 Idiomatic Phrases Game
迪杰斯特拉单源最短路算法.对成语进行预处理.做出邻接矩阵即可. #include<cstdio> #include<cstring> #include<cmath> ...
- ZOJ-2750 Idiomatic Phrases Game---Dijk最短路
题目链接: https://vjudge.net/problem/ZOJ-2750 题目大意: 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程 ...
随机推荐
- FJ省队集训DAY5 T1
思路:考试的时候打了LCT,自以为能过,没想到只能过80.. 考完一想:lct的做法点数是100W,就算是nlogn也会T. 讲一下lct的做法把:首先如果一条边连接的两个点都在同一个联通块内,那么这 ...
- 自制单片机之八……USB-ISP下载线
现在的笔记本包括台式机都渐渐地舍弃了并口.串口:很多网友也跟我说,台式没有并口了,下载线没法用了,让我帮他想想办法.看来做个USB-ISP下载线是势在必行了. 在网上搜了下,主要有两种方案,一种是用F ...
- qtpanel
https://github.com/MadFishTheOne/qtpanel https://github.com/xiangzhai/qtpanel
- wordpress提速插件
auto-remove-googles-url插件,替换前后台国外字体!访问速度有较大提高!可百度搜索auto-remove-googles-url下载,如在wp后台进行插件安装即可
- PHP null常量和null字节的区别
在学习isset()时,看到了这句话:“如果已经使用 unset() 释放了一个变量之后,它将不再是 isset().若使用 isset() 测试一个被设置成 NULL 的变量,将返回 FALSE.同 ...
- 关于bootstrap--列表(ol、ul)
1.list-unstyled : 在<ol>(有序列表)</ol><ul>(无序列表)</ul>中加入class="list-styled& ...
- 分页标签:pager-taglib使用指南
一简介, Pager-taglib,支持多种风格的分页显示.实际上她是一个Jsp标签库,为在JSP上显示分页信息而设计的一套标签,通过这些标签的不同的组合,会形成多种不一样的分页页面,风格各异,她自带 ...
- wcf简单的创建和运用
创建一个控制台应用程序,命名为wcftest,并在同一解决方案中添加一个wcf服务应用程序 在wcf项目中会自动生成Service1.svc服务程序文件和IService1.cs契约接口 IServi ...
- 改进的newlisp编译脚本,只需要配置
前面有一篇Say bye to CMake and Makefile我开始用自己编写的newlisp脚本替代CMake,今天对前面的进行改进. 改进部分是: 1. newlisp armory模块的引 ...
- Android Studio使用技巧系列教程(二)
尊重劳动成果,转载请注明出处:http://blog.csdn.net/growth58/article/details/46764575 关注新浪微博:@于卫国 邮箱:yuweiguocn@gmai ...