【题目链接】

点击打开链接

【算法】

最短路,注意不能用dijkstra,要用SPFA

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100 typedef long long LL; LL i,M,N,x,t,v,ans,p;
LL dist[MAXN+],vis[MAXN+],level[MAXN+];
vector<pair<LL,LL> > E[MAXN+]; template <typename T> void read(T &x) {
int f=; char c = getchar(); x=;
for (; !isdigit(c); c = getchar()) { if (c=='-') f=-; }
for (; isdigit(c); c = getchar()) x=x*+c-'';
x*=f;
} void spfa(int low,int high) {
int i,to,cost;
queue<LL> q;
memset(vis,,sizeof(vis));
for (i = ; i <= N; i++) dist[i] = 2e9;
dist[] = ; vis[] = ;
q.push();
while (!q.empty()) {
x = q.front(); q.pop();
vis[x] = ;
for (i = ; i < E[x].size(); i++) {
to = E[x][i].first;
cost = E[x][i].second;
if ((level[to] >= low) && (level[to] <= high)) {
if (dist[x] + cost < dist[to]) {
dist[to] = dist[x] + cost;
if (!vis[to]) {
vis[to] = ;
q.push(to);
}
}
}
}
}
} int main() { read(M); read(N);
for (i = ; i <= N; i++) {
read(p); read(level[i]); read(x);
E[].push_back(make_pair(i,p));
while (x--) {
read(t); read(v);
E[t].push_back(make_pair(i,v));
}
} ans = 2e9;
for (i = level[] - M; i <= level[]; i++) {
spfa(i,i+M);
ans = min(ans,dist[]);
} cout<< ans << endl; return ; }

【ZJOI 2002】 昂贵的聘礼的更多相关文章

  1. POJ1062昂贵的聘礼[最短路建模]

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 45892   Accepted: 13614 Descripti ...

  2. 昂贵的聘礼(dijkstra)

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38549   Accepted: 11158 Descripti ...

  3. POJ 1062 昂贵的聘礼

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

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

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

  5. Poj OpenJudge 百练 1062 昂贵的聘礼

    1.Link: http://poj.org/problem?id=1062 http://bailian.openjudge.cn/practice/1062/ 2.Content: 昂贵的聘礼 T ...

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

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

  7. POJ1062昂贵的聘礼(dijkstra)

    昂贵的聘礼 题目大意是说有N个物品,每个物品都有自己的价格,但同时某些物品也可以由其他的(可能不止一个)替代品,这些替代品的价格比较“优惠”,问怎么样选取可以让你的花费最少来购买到物品1 由于有N个物 ...

  8. 昂贵的聘礼--POJ1062

    昂贵的聘礼 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submiss ...

  9. POJ1062 昂贵的聘礼 【DFS】

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37475   Accepted: 10816 Descripti ...

  10. POJ1062昂贵的聘礼(经典) 枚举区间 +【Dijkstra】

    <题目链接>                   昂贵的聘礼 Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用1000 ...

随机推荐

  1. P2085 最小函数值 洛谷

    https://www.luogu.org/problem/show?pid=2085 题目描述 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci (x∈N*) ...

  2. Java运算基础

    计算机对负数的运算 =  先取绝对值的原码----> 然后取反,----->+1   这是负数的补码表示 例如  -5       5的原码= 0000,0101  取反   1111,1 ...

  3. Spring实战Day7面向切面编程术语介绍

    #### 面向切面编程 为什么需要切面? 有些功能需要在应用中的多个地方使用到,但是我们又不想在着每个地方都调用他们 切面术语 通知(advice):切面需要完成的工作 通知的类型(什么时间完成工作) ...

  4. jquery+css实现邮箱自动补全

    今天在公司做一个电子商务网站的注册会员时,要求用户在电子邮箱文本框中输入时,给与热点提示常用的电子邮箱,帮助用户选择,提高体验效果.下面是用Jquery+css实现的邮箱自动补全,供大家参考和学习. ...

  5. Activiti Model Editor组件

    通过Activiti Modeler架构图可知,Activiti Explorer采用的是Vaadin框架. Vaadin 是一种 Java Web 应用程序的开发框架, 其设计目标是便利地创建和维护 ...

  6. 国内90%以上的 iOS 开发者,对 APNs 的认识都是错的

    转:http://toutiao.com/a6276578687162040578/?tt_from=weixin&utm_campaign=client_share&app=news ...

  7. weex splash页面

    1.Splash.vue <!-- splash页面 --> <template> <div class="wrap" @focus="ro ...

  8. 基于bootstrap_信息采集

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. reviews of learn python3 the hard way

    Almost every time,I try my best to write a long review of the book I have read. But this time I want ...

  10. TC SRM 583 DIV 2

    做了俩,rating涨了80.第二个题是关于身份证的模拟题,写的时间比较长,但是我认真检查了... 第三个题是最短路,今天写了写,写的很繁琐,写的很多错. #include <cstring&g ...