提出了一个错误的算法 以为能优化到只运行两次dij

然而我还是too naive 还是乖乖dij n 次吧...

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#define INF 0x3F3F3F3F
using namespace std; typedef pair<int, int> pii;
struct cmp{
bool operator () (const pii a, const pii b){
return a.first > b.first;
}
}; int map[][], val[][], lev[];
int m, n; int dij()
{
int dist[];
priority_queue<pii, vector<pii>, cmp> q;
memset(dist, 0x3f, sizeof dist);
dist[] = ;
q.push(make_pair(, ));
while(!q.empty()){
pii u = q.top();
q.pop();
if(u.first > dist[u.second]) continue;
for(int i = ; i <= n; i++){
if(dist[i] > dist[u.second] + val[u.second][i]){
dist[i] = dist[u.second] + val[u.second][i];
q.push(make_pair(dist[i], i));
}
}
}
return dist[];
} int main()
{
memset(map, 0x3f, sizeof val);
scanf("%d%d", &m, &n);
for(int i = ; i <= n; i++){
int x, y, p;
scanf("%d%d%d", &map[][i], &lev[i], &x);
while(x--){
scanf("%d%d", &y, &p);
map[y][i] = p;
}
}
int ans = INF;
for(int i = ; i <= m; i++){
memset(val, 0x3f, sizeof val);
for(int x = ; x <= n; x++){
if(x == || (lev[x] >= lev[] - m + i && lev[x] <= lev[] + i)){
for(int y = ; y <= n; y++){
if(lev[y] >= lev[] - m + i && lev[y] <= lev[] + i){
val[x][y] = map[x][y];
}
}
}
}
ans = min(dij(), ans);
//printf("%d ~ %d : %d\n", lev[1] - m + i, lev[1] + i, ans);
}
printf("%d\n", ans);
return ;
}

kuangbin_ShortPath M (POJ 1062)的更多相关文章

  1. POJ 1062 昂贵的聘礼

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

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

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

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

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

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

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

  5. POJ 1062 ( dijkstra )

    http://poj.org/problem?id=1062 一个中文题,一个多月之前我做过,当时我是用搜索写的,不过苦于卡在无法确定等级关系,所以就错了. 看了别人的博客后,我还是不是很理解所谓的枚 ...

  6. POJ 1062 昂贵的聘礼 最短路 难度:0

    http://poj.org/problem?id=1062 #include <iostream> #include <cstring> #include <queue ...

  7. poj 1062(有限制的最短路)

    题目链接:http://poj.org/problem?id=1062 思路:要求对于最短路上的点,不能出现等级之差大于m,于是我们可以枚举,假设酋长的等级为level,于是这个区间范围[level- ...

  8. poj 1062 昂贵的聘礼(最短路 dijk+枚举)

    终于A 了,这题做着真麻烦 题目:http://poj.org/problem?id=1062 dijk 一般用于正权有向图 此题的关键在于等级限制的处理,最好的办法是采用枚举,即假设酋长等级为5,等 ...

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

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

随机推荐

  1. 在T-SQL中访问远程数据库(openrowset、opendatasource、openquery)

    1.  启用Ad Hoc Distributed Queries 在使用openrowset/opendatasource前要先启用Ad Hoc Distributed Queries服务,因为这个服 ...

  2. Chapter 4: Tomcat Default Connector

    一.概述 第三章介绍的connector是一个很好的学习工具,但是我们还可以做的更多.这一章介绍的是Tomcat4默认的connector. 一个Tomcat的connector是一个独立的模块,能够 ...

  3. ios上 更改 状态栏(UIStatusBar)

    摘要 ios上 更改状态栏(UIStatusBar)的颜色 ios UIStatusBar statusBar 状态栏 更改状态栏颜色 目录[-] IOS上 关于状态栏的相关设置(UIStatusBa ...

  4. ++index 与 index++

    摘自:C++标准程序库

  5. 【LeetCode OJ】Triangle

    Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j < ...

  6. 【LEETCODE OJ】Single Number

    Prolbem link: http://oj.leetcode.com/problems/single-number/ This prolbem can be solved by using XOR ...

  7. PHP Filter

    PHP filters are used to validate and sanitize external input. Validating data is determine if the da ...

  8. Android沉浸式(侵入式)标题栏(状态栏)Status(一)

     Android沉浸式(侵入式)标题栏(状态栏)Status(一) 现在越来越多的APP设计采用这种称之为沉浸式状态栏(Status)的设计,这种沉浸式状态栏又称之"侵入式"状 ...

  9. Oracle查看表结构的几种方法(转后加工)

    1. DESCRIBE 命令使用方法如下:SQL> describe WX_ADVANCEUP (WX_ADVANCEUP为表名)显示的结果如下: 名称                     ...

  10. 斜率dp cdq 分治

    f[i] = min { f[j] + sqr(a[i] - a[j]) } f[i]= min { -2 * a[i] * a[j] + a[j] * a[j] + f[j] } + a[i] * ...