// 题意 : 一个人要去旅行 给你起点和终点 求最少花费  其中花费为经过路径的总费用减去该路径的中的最大花费段
// 直接搜索 稍微加了个剪枝 主要是数据规模小
#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define MOD 1000000007
#define maxn
map<string,int> mp;
vector <int >V[];
bool visit[];
int rc[][];
char str1[],str2[];
char ss[],ts[];
int s,t;
int ans;
void dfs(int u,int sum,int mx){
// if(u==t) return;
visit[u]=true;
if(sum-mx>ans) return; // 加了个小剪枝
int i,v,ts,tm;
int len=V[u].size();
for(i=;i<len;i++){
v=V[u][i];
if(!visit[v]){
ts=sum+rc[u][v];
tm=max(mx,rc[u][v]);
if(v==t){
ans=min(ans,ts-tm);
return ;
}
dfs(v,ts,tm);
visit[v]=false;
}
} }
int main(){
int m;
int n;
while(scanf("%s %s",ss,ts)!=EOF){
scanf("%d",&m);
int i,val;
int u,v;
n=;
map<string,int>::iterator it;
for(i=;i<m;i++){
scanf("%s %s %d",str1,str2,&val);
it=mp.find(str1);
if(it!=mp.end()){
u= mp[str1];
}
else{
u=n++;
mp[str1]=u;
}
it=mp.find(str2);
if(it!=mp.end()){
v= mp[str2];
}
else{
v=n++;
mp[str2]=v;
}
V[u].push_back(v);
rc[u][v]=val;
}
s=mp[ss];
t=mp[ts];
memset(visit,,sizeof(visit));
ans=MOD;
//printf("%d %d\n",s,t);
dfs(s,,);
printf("%d\n",ans);
mp.clear();
for(i=;i<n;i++)
V[i].clear();
}
}

zoj 2027 Travelling Fee的更多相关文章

  1. Travelling Fee(Dijlstra——最短路问题变型)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2027 题目: Samball is going to trav ...

  2. ZOJ1027 Travelling Fee(DP+SPFA)

    给一张有向无环图,边都有花费,从某点到某点走的那条路径上的那一条花费最多的边可以省掉,问从起点到终点的最少花费的多少, 往DP想的话,就可以写出这个状态dp[u][mx],表示到达u点已经省掉的花费为 ...

  3. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  4. Travelling

    Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  6. HDU-3001 Travelling

    http://acm.hdu.edu.cn/showproblem.php?pid=3001 从任何一个点出发,去到达所有的点,但每个点只能到达2次,使用的经费最小.三进制 Travelling Ti ...

  7. hdu 3001 Travelling (TSP问题 )

    Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. hdu 3001 Travelling(状态压缩 三进制)

    Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. Travelling(spfa+状态压缩dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3001 Travelling Time Limit: 6000/3000 MS (Java/Others ...

随机推荐

  1. C#文件对话框,一次多选文件设置

    OpenFileDialog ofd = new OpenFileDialog();ofd.Multiselect = true;if (ofd.ShowDialog() == DialogResul ...

  2. MATLAB——PLOT绘图

    MATLAB——PLOT绘图 格式化绘图: 1.color: b g  r c m y k w blue green red  cyan magenta yellow black white 2.ty ...

  3. 如何解决VS启动越来越慢

    VS2013 用久后,现在启动和打开项目变得很慢 解决方案: A.清理缓存 VS2010清理缓存:启用vs2010命令行工具:在vs2010命令提示符下,执行devenv.exe /resetuser ...

  4. 【WCF--初入江湖】03 配置服务

    03 配置服务 数据库 生成数据库脚本: CREATE DATABASE [EmployeeDb]; CREATE TABLE [dbo].[T_Employee]( [Id] [,) NOT NUL ...

  5. mac os 下如何清除/切换svn eclipse插件的用户

    以mac os x为例(Unix/Linux类似), 1.打开命令行窗口,即用户的根目录(用户的home目录) $ ls -al ... drwxr-xr-x   6 linxyz  staff   ...

  6. intellij idea 12、13 win8 下 中文输入覆盖的问题(搜狗输入法或者其他输入法)

    最近升级到idea12,发现中文输入存在问题,输入中文的时候会出现空格,并且覆盖后面的字符,这个问题让我很郁闷. 假设idea的安装位置为:D:\Program Files\JetBrains\Int ...

  7. linux系统快速查看进程pid的方法

    一个很简单的命令,pgrep,可以迅速定位包含某个关键字的进程的pid:使用这个命令,再也不用ps aux 以后去对哪个进程的pid了 一个很简单的命令,pgrep,可以迅速定位包含某个关键字的进程的 ...

  8. Django admin site(三)InlineModelAdmin

    InlineModelAdmin class InlineModelAdminclass TabularInlineclass StackedInline 举例,有两个Model: from djan ...

  9. json-lib 中关于null与"null"

    总感觉json-lib里面关于null和"null"的处理非常不合理,或者说是bug,去了json-lib的网站,最后一次更新是10年了... 发现官方网站第一段就说json-li ...

  10. JBPM4 常用表结构

    JBPM4 常用表结构 第一部分:表结构说明 Jbpm4 共有18张表,如下,其中红色的表为经常使用的表   一:资源库与运行时表结构 1.  JBPM4_DEPLOYMENT 流程定义表 2.  J ...