思路:构造最短路模型,抽象出来一个源点,这个源点到第i个点的费用就是price[i],然后就能抽象出图来,终点是1.

任意两个人之间都有等级限制,就枚举所有最低等级限制,然后将不再区间[min_lev, min_lev+m]区间的点都删除,就能进行Dijkstra算法了。

AC代码

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 100+5;
int price[maxn], lev[maxn];
int cost[maxn][maxn], vis[maxn], d[maxn];
int n, m;

int Dijkstra() {
	memset(d, inf, sizeof(d));
	d[0] = 0;
	for(int i = 0; i <= n; ++i) {
		int x = 0, tmp = inf;
		for(int y = 0; y <= n; ++y) if(!vis[y] && d[y] <= tmp) tmp = d[x=y];
		if(vis[x]) continue;
		vis[x] = 1;
		for(int y = 0; y <= n; ++y) if(!vis[y]) d[y] = min(d[y], d[x] + cost[x][y]);
	}
	return d[1];
}

int main() {
	while(scanf("%d%d", &m, &n) == 2) {
		int r, x, c;
		memset(cost, inf, sizeof(cost));
		for(int i = 1; i <= n; ++i) {
			scanf("%d%d%d", &price[i], &lev[i], &r);
			cost[0][i] = price[i]; //源点0到各点的费用
			for(int j = 0; j < r; ++j) {
				scanf("%d%d", &x, &c);
				cost[x][i] = min(cost[x][i], c);
			}
		}
		int ans = inf;
		for(int i = 1; i <= n; ++i) {
			int min_lev = lev[i]; //最低等级
			memset(vis, 0, sizeof(vis));
			for(int j = 1; j <= n; ++j) {
				if(lev[j] < min_lev || lev[j] - min_lev > m) vis[j] = 1;
			}
			int dis = Dijkstra();
			ans = min(ans, dis);
		}
		printf("%d\n", ans);
	}
	return 0;
}

如有不当之处欢迎指出!

POJ - 1062 昂贵的聘礼 Dijkstra的更多相关文章

  1. 最短路(Dijkstra) POJ 1062 昂贵的聘礼

    题目传送门 /* 最短路:Dijkstra算法,首先依照等级差距枚举“删除”某些点,即used,然后分别从该点出发生成最短路 更新每个点的最短路的最小值 注意:国王的等级不一定是最高的:) */ #i ...

  2. POJ 1062 昂贵的聘礼(图论,最短路径)

    POJ 1062 昂贵的聘礼(图论,最短路径) Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女 ...

  3. poj 1062 昂贵的聘礼 (dijkstra最短路)

    题目链接:http://poj.org/problem?id=1062 昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  4. POJ 1062 昂贵的聘礼(带限制条件的dijkstra)

    题目网址:http://poj.org/problem?id=1062 题目: 昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  5. POJ - 1062 昂贵的聘礼(最短路Dijkstra)

    昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u SubmitStatus Descr ...

  6. POJ 1062 昂贵的聘礼

    C - 昂贵的聘礼 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit St ...

  7. 最短路POJ 1062 昂贵的聘礼

    C - 昂贵的聘礼 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit St ...

  8. POJ -1062 昂贵的聘礼(前向星 &amp;&amp; SPFA)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/30299671 题目链接:id=1062&qu ...

  9. POJ 1062 昂贵的聘礼 (最短路)

    昂贵的聘礼 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/M Description 年轻的探险家来到了一个印第安部落里.在那里 ...

随机推荐

  1. junit断言总结

    我们平时编写自己的测试类,如果没有断言,那么就没写测试的必要了. JUnit框架用一组assert方法封装了最常见的测试任务.这些assert方法可以极大地简化单元测试的编写. Assert类包含了一 ...

  2. Servlet--HttpUtils类

    定义 public class HttpUtils 收集 HTTP Servlet 使用的静态的有效的方法. 方法 1.getRequestURL public static StringBuffer ...

  3. 不免费的PacMan

    课程内容介绍: 本套课程适合以下人士: - 免费资料没教会你游戏开发的: - 学了Unity基础不知道怎么用在游戏项目里的: - 想快速开发一款好玩的游戏的: - 想学游戏不知道如何入门的: - 对游 ...

  4. Community Stories: Cinemachine and Timeline——Community Stories: Cinemachine and Timeline

    Community Stories: Cinemachine and Timeline 社区故事:Cinemachine 和 Timeline Adam Myhill, 八月 25, 2017 原文: ...

  5. javascript:Json 和数组的遍历

    首先看代码示例var json={a:1,b:2,c:3}; //json var array={1,2,3}; //数组 alert(json.a); //弹出1 或alert(json['a']) ...

  6. SpringMVC源码情操陶冶-DispatcherServlet类简析(一)

    阅读源码有利于陶冶情操,此文承接前文SpringMVC源码情操陶冶-DispatcherServlet父类简析 注意:springmvc初始化其他内容,其对应的配置文件已被加载至beanFactory ...

  7. Oracle RAC基本概念

    原文链接:http://tech.it168.com/a2012/0814/1384/000001384756_all.shtml 不同的集群产品都有自己的特点,RAC的特点包括如下几点: ·双机并行 ...

  8. Python基础篇(四)

    Python中的字典类似于Java中的Map,数据以键值对的形式存储. 字典可以用以下的方式使用: >>> phonebook = {"alice":" ...

  9. 最大流模版 EK

    EK算法基于增广路的思想,易于理解,但由于低效并不被经常使用 #include <iostream> #include <cstdio> #include <algori ...

  10. BZOJ 1815: [Shoi2006]color 有色图 [Polya DFS 重复合并]

    传送门 题意: 染色图是无向完全图,且每条边可被染成k种颜色中的一种.两个染色图是同构的,当且仅当可以改变一个图的顶点的编号,使得两个染色图完全相同.问N个顶点,k种颜色,本质不同的染色图个数(模质数 ...