当前位置:网站首页>AcWing 903. Expensive bride price solution (the shortest path - building map, Dijkstra)
AcWing 903. Expensive bride price solution (the shortest path - building map, Dijkstra)
2022-07-02 19:40:00 【Mr. Qiao Da】
AcWing 903. Expensive betrothal gifts
The difficulty of this problem is building a map , The trick is to establish a virtual starting point , Let each road become a virtual starting point ( In the picture S, Points in the code 0) Reach the end point ( spot 1) A path for , Then find the shortest path 
#include<bits/stdc++.h>
using namespace std;
const int N = 110, INF = 0x3f3f3f3f;
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define rop(i, a, b) for(int i = a; i < b; i ++ )
int w[N][N];
int level[N]; // Master level
int d[N];
int n, m;
bool st[N];
int dijkstra(int down, int up){
memset(d, 0x3f, sizeof d);
memset(st, 0, sizeof st);
d[0] = 0;
rep(i, 1, n){
int t = -1;
rep(j, 0, n){
// What we are looking for here is Li i Point the nearest point , So include the virtual starting point 0
if(!st[j] && (t == -1 || d[t] > d[j])) t = j; // This step is to find the point with the smallest distance at present and update the distance of other points , So we must first judge whether this point has been used
}
st[t] = true; // Marking this point has been used , Because each point is the closest when it is first used , Later, it will not be updated to a smaller distance
rep(j, 1, n){
if(level[j] >= down && level[j] <= up){
d[j] = min(d[j], d[t] + w[t][j]);
}
}
}
return d[1];
}
int main()
{
cin>>m>>n;
memset(w, 0x3f, sizeof w);
rep(i, 1, n) w[i][i] = 0;
rep(i, 1, n){
int price, cnt;
cin>>price>>level[i]>>cnt;
w[0][i] = min(w[0][i], price);
while(cnt -- ){
int pr, id;
cin>>id>>pr;
w[id][i] = min(w[id][i], pr); // The question is id Can replace i, When building the map id towards i The edge of , So it should be w[id][i]
}
}
int res = INF;
rep(i, level[1] - m, level[1]){
res = min(res, dijkstra(i, i + m));
}
cout<<res<<endl;
return 0;
}
边栏推荐
- AcWing 1134. 最短路计数 题解(最短路)
- Zabbix5 client installation and configuration
- 守望先锋世界观架构 ——(一款好的游戏是怎么来的)
- Gamefi chain game system development (NFT chain game development function) NFT chain game system development (gamefi chain game development source code)
- KT148A语音芯片ic的软件参考代码C语言,一线串口
- AcWing 383. Sightseeing problem solution (shortest circuit)
- Is there any security guarantee for the ranking of stock and securities companies
- [pytorch learning notes] tensor
- Embedded (PLD) series, epf10k50rc240-3n programmable logic device
- 搭建主从模式集群redis
猜你喜欢

定了,就是它!

守望先锋世界观架构 ——(一款好的游戏是怎么来的)

Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode

SQLite 3.39.0 release supports right external connection and all external connection

Introduction to program ape (XII) -- data storage

rxjs Observable 自定义 Operator 的开发技巧

AcWing 342. 道路与航线 题解 (最短路、拓扑排序)

良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!

基于SSM实现网上购物商城系统

mysql函数
随机推荐
golang:[]byte转string
MySQL advanced (Advanced) SQL statement
Virtual machine initialization script, virtual machine mutual secret key free
How to avoid duplicate data in gaobingfa?
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
AcWing 181. 回转游戏 题解(搜索—IDA*搜索)
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
KS004 基于SSH通讯录系统设计与实现
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
Introduction to mongodb chapter 03 basic concepts of mongodb
AcWing 341. 最优贸易 题解 (最短路、dp)
c语言里怎么设立优先级,细说C语言优先级
《重构:改善既有代码的设计》读书笔记(上)
Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
Golang:[]byte to string
MySQL
Getting started with typescript
Detailed tutorial on installing stand-alone redis
[ERP software] what are the dangers of the secondary development of ERP system?
checklistbox控件用法总结