【题目链接】

点击打开链接

【算法】

最短路,注意不能用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. meta标签集

    html中的meta总结: 0.声明文档使用的字符编码: <meta charset='utf-8'/> 1.优先使用 IE 最新版本和 Chrome : <meta http-eq ...

  2. 八皇后问题Python实现

    八皇后问题描述 问题: 国际象棋棋盘是8 * 8的方格,每个方格里放一个棋子.皇后这种棋子可以攻击同一行或者同一列或者斜线(左上左下右上右下四个方向)上的棋子.在一个棋盘上如果要放八个皇后,使得她们互 ...

  3. Struts2的验证框架简单吗?

    Struts2验证框架是基于Struts拦截器开发的,具有良好的扩展性:一般的验证都可以支持.现在我们以一个注册验证的例子进行总结: 新建一个model,User: public class User ...

  4. java多线程02-----------------synchronized底层实现及JVM对synchronized的优化

    java多线程02-----------------synchronized底层实现及JVM对synchronized的优化 提到java多线程,我们首先想到的就是synchronized关键字,它在 ...

  5. 使用ftrace学习linux内核函数调用

    http://www.cnblogs.com/pengdonglin137/articles/4752082.html 转载: http://blog.csdn.net/ronliu/article/ ...

  6. flask-limiter限制单个IP访问的频率和次数

    Flask-Limiter provides rate limiting features to flask routes. It has support for a configurable bac ...

  7. vue2.0 常用的 UI 库

    1.mint-ui 安装: npm install mint-ui --save 使用: main.js // MintUI组件库 import MintUI from 'mint-ui' impor ...

  8. 基于SpringMVC框架使用ECharts3.0实现堆叠条形图的绘制(下篇)

    <script type="text/javascript"> $().ready(function() { var myChart = echarts.init(do ...

  9. DBExecutor android 数据库框架

    https://github.com/eltld/DBExecutor android 数据库框架,sqlite database

  10. MySQL中给自定义的字段查询结果添加排名的方法

    我正在用 MySQL 客户端的时候,突然想到如果可以给查询结果添加排名该多好啊,然后就找到了一个简单的解决办法. 下面是一个示例表的数据:  然后我们要根据 Roll_No 字段进行排序并给出排名,我 ...