最短路(Dijkstra) POJ 1062 昂贵的聘礼
/*
最短路:Dijkstra算法,首先依照等级差距枚举“删除”某些点,即used,然后分别从该点出发生成最短路
更新每个点的最短路的最小值
注意:国王的等级不一定是最高的:)
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <cstring>
#include <string>
using namespace std; const int MAXN = 1e2 + ;
const int INF = 0x3f3f3f3f; int d[MAXN];
int cost[MAXN][MAXN];
int x[MAXN];
int lv[MAXN];
int used[MAXN]; int Dijkstra(int n)
{
for (int i=; i<=n; ++i) d[i] = cost[][i]; for (int i=; i<=n; ++i)
{
int x = ;
int mn = INF;
for (int j=; j<=n; ++j)
{
if (!used[j] && d[j] < mn) mn = d[x=j];
}
if (x == ) break;
used[x] = ;
for (int j=; j<=n; ++j)
{
if (!used[j] && cost[x][j] > )
d[j] = min (d[j], d[x] + cost[x][j]);
}
} return d[];
} int main(void) //POJ 1062 昂贵的聘礼
{
//freopen ("C.in", "r", stdin); int n, m; while (~scanf ("%d%d", &m, &n))
{
memset (used, , sizeof (used));
memset (d, , sizeof (d));
memset (cost, , sizeof (cost));
for (int i=; i<=n; ++i)
{
scanf ("%d%d%d", &cost[][i], &lv[i], &x[i]);
for (int j=; j<=x[i]; ++j)
{
int t, u;
scanf ("%d%d", &t, &u);
cost[t][i] = u;
}
} int tmp, ans = INF, maxlv;
for (int i=; i<=n; ++i)
{
maxlv = lv[i];
for (int j=; j<=n; ++j)
{
if (lv[j] > maxlv || maxlv - lv[j] > m) used[j] = ;
else used[j] = ;
}
tmp = Dijkstra (n);
ans = min (ans, tmp);
} printf ("%d\n", ans);
} return ;
}
最短路(Dijkstra) POJ 1062 昂贵的聘礼的更多相关文章
- POJ 1062 昂贵的聘礼(图论,最短路径)
POJ 1062 昂贵的聘礼(图论,最短路径) Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女 ...
- poj 1062 昂贵的聘礼 (dijkstra最短路)
题目链接:http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submission ...
- POJ - 1062 昂贵的聘礼(最短路Dijkstra)
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u SubmitStatus Descr ...
- 最短路POJ 1062 昂贵的聘礼
C - 昂贵的聘礼 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit St ...
- POJ 1062 昂贵的聘礼(带限制条件的dijkstra)
题目网址:http://poj.org/problem?id=1062 题目: 昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- POJ 1062 昂贵的聘礼 (最短路)
昂贵的聘礼 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/M Description 年轻的探险家来到了一个印第安部落里.在那里 ...
- poj 1062 昂贵的聘礼 (有限制的最短路)
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56594 Accepted: 17083 Descripti ...
- POJ 1062 昂贵的聘礼(最短路中等题)
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 51879 Accepted: 15584 Descripti ...
- POJ 1062 昂贵的聘礼
C - 昂贵的聘礼 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit St ...
随机推荐
- HDU 2577 How to Type(dp题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...
- [Effective JavaScript 笔记]第46条:使用数组而不要使用字典来存储有序集合
对象属性无序性 js对象是一个无序属性集合. var obj={}; obj.a=10; obj.b=30; 属性a和属性b并没有谁前谁后之说.for...in循环,先输出哪个属性都有可能.获取和设置 ...
- Unity3d与iOS交互开发——接入平台SDK必备技能
原地址:http://www.2cto.com/kf/201401/273337.html# 前言废话:开发手机游戏都知道,你要接入各种平台的SDK.那就需要Unity3d与iOS中Objective ...
- 基于 MeanShift 算法的目标跟踪问题研究
参考:http://www.cnblogs.com/tornadomeet/archive/2012/03/15/2398769.html MeanShift 算法作为一种基于特征的跟踪方法,基本思想 ...
- Java 7 的7个新特性
1.对集合类的语言支持:(??) 2.自动资源管理: 3.改进的通用实例创建类型推断:(??) 4.数字字面量下划线支持:(√) 5.switch中使用string:(√) 6.二进制字面量:(√) ...
- Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- 利用FFmpeg生成视频缩略图 2.1.6
利用FFmpeg生成视频缩略图 1.下载FFmpeg文件包,解压包里的\bin\下的文件解压到 D:\ffmpeg\ 目录下. 下载地址 http://ffmpeg.zeranoe.com/build ...
- 3.前端笔记之JavaScript基础
作者:刘耀 部分内容参考一下链接 参考: http://www.cnblogs.com/wupeiqi/articles/5369773.html http://javascript.ruanyife ...
- Extjs给gridPanel添加单价双击事件和获取当前行的数据
有两个小属性,如下 this.on('rowdblclick', this.readContent, this); this.on('cellclick', this.gridCellClick, t ...
- Gym 100801D Distribution in Metagonia (数学思维题)
题目:传送门.(需要下载PDF) 题意:t组数据,每组数据给定一个数ni(1 ≤ ni ≤ 10^18),把ni拆成尽可能多的数,要求每个数的素因子只包含2和3,且这些数不能被彼此整除,输出一共能拆成 ...