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 题目大意: 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程 ...
随机推荐
- 深入理解7816(5)-----关于文件DF/EF/MF/FID/AID/SFI
刚开始接触CPU卡的时候,对于各种文件.应用的定义容易模糊不清,通常不能准确地界定什么是文件?什么是应用?DF和EF的区别真的就像计算机里的目录和文档那样吗?FID.AID.SFI这些概念都在什么时候 ...
- jquery获得select选中索引
select选中索引有好多方式, 这两种方式取不到索引值这两种方式取不到索引值这两种方式取不到索引值这两种方式取不到索引值 $('#someId').find('option:select ...
- Cmake编译成静态库
To build OpenCV as static library you need to set BUILD_SHARED_LIBS flag to false/off: cmake -DBUILD ...
- JVM JMM
- Underscore.js(1.7.0) 中文文档 Underscore.js 入门
原文地址:http://www.css88.com/doc/underscore/ Underscore.js 入门 http://www.tuicool.com/articles/jQ3IfeR
- [IOS]包含增删改查移动的tableView展示+plist文件保存+程序意外退出保存Demo
做一个tableView,包含增删改移动功能,并且修改值的时候,在按home键的时候会自动保存.如果可以的话使者保存自定义的类数组保存到plist中. 实现步骤: 1.创建一个SingleViewAp ...
- HTML5 拼图游戏
点击之后被选中的切片会变为透明 源代码 点击打开链接
- 马士兵Servlet&Jsp学习
Servlet&JSP 1>http常见错误信息: 404--url地址找不找, 403--禁止访问 500--服务器内部错误 2>Servlet的生命周期: *生命全过 ...
- Android Studio IDE 所遇问题汇总
[窗体视图无法显示] 在/res/values/styles.xml文件中,修改一下内容 <!-- Base application theme. --><style nam ...
- .NET 4.0 兼容 .NET 2.0 的方法
使用.net开发桌面应用,广大亲门最头疼的莫过于客户端部署的问题.基于.net 2.0 的winfrom程序因为 Framework 的分发包大小为20M左右还好解决,不幸的是如果项目中使用了Wcf, ...