sincerit 1301 Jungle Roads

本文深入探讨了最小生成树算法中的普里姆算法,通过一个具体的道路网络维护问题实例,详细解释了如何使用该算法来寻找连接所有村庄的最低成本路径。文章提供了完整的C++代码实现,展示了算法的具体应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1301 Jungle Roads
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10249 Accepted Submission(s): 7518

Problem Description

The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain. The Council of Elders must choose to stop maintaining some roads. The map above on the left shows all the roads in use now and the cost in aacms per month to maintain them. Of course there needs to be some way to get between all the villages on maintained roads, even if the route is not as short as before. The Chief Elder would like to tell the Council of Elders what would be the smallest amount they could spend in aacms per month to maintain roads that would connect all the villages. The villages are labeled A through I in the maps above. The map on the right shows the roads that could be maintained most cheaply, for 216 aacms per month. Your task is to write a program that will solve such problems.
在这里插入图片描述

The input consists of one to 100 data sets, followed by a final line containing only 0. Each data set starts with a line containing only a number n, which is the number of villages, 1 < n < 27, and the villages are labeled with the first n letters of the alphabet, capitalized. Each data set is completed with n-1 lines that start with village labels in alphabetical order. There is no line for the last village. Each line for a village starts with the village label followed by a number, k, of roads from this village to villages with labels later in the alphabet. If k is greater than 0, the line continues with data for each of the k roads. The data for each road is the village label for the other end of the road followed by the monthly maintenance cost in aacms for the road. Maintenance costs will be positive integers less than 100. All data fields in the row are separated by single blanks. The road network will always allow travel between all the villages. The network will never have more than 75 roads. No village will have more than 15 roads going to other villages (before or after in the alphabet). In the sample input below, the first data set goes with the map above.

The output is one integer per line for each data set: the minimum cost in aacms per month to maintain a road system that connect all the villages. Caution: A brute force solution that examines every possible set of roads will not finish within the one minute time limit.

Sample Input
9
A 2 B 12 I 25
B 3 C 10 H 40 I 8
C 2 D 18 G 55
D 1 E 44
E 2 F 60 G 38
F 0
G 1 H 35
H 1 I 35
3
A 2 B 10 C 40
B 1 C 20
0

Sample Output
216
30

/*最小生成树--普里姆算法*/
#include <iostream>
#include <vector> 
#include <cstring>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f
int map[30][30], n;
// 一个集合p表示在最小生成树里的点,一个表示不在最小生成树里的点
// disance[i]表示p里的点到i点最短的距离 
int disance[30];
int prim(int cur) {
  int vis[30] = {0}, index = cur, sum = 0;
  for (int i = 1; i <= n; i++) disance[i] = map[index][i];
  disance[index] = 0;
  vis[index] = 1;
  for (int i = 1; i < n; i++) {  // 要找多少个顶点就循环多少次,因为第一个不用找了就还剩n-1个 
    int mi = INF;
    for (int j = 1; j <= n; j++) {
      if (!vis[j] && mi > disance[j]) {
        mi = disance[j];
        index = j;
      }
    }
    sum += mi;
    vis[index] = 1;
    for (int k = 1; k <= n; k++) {
      if (!vis[k] && disance[k] > map[index][k]) disance[k] = map[index][k];
    }
  }
  return sum;
} 
int main() {
  while (cin >> n, n) {
    char x, y;
    int w, len;
    memset(map, INF, sizeof(map)); 
    for (int i = 1; i < n; i++) {  // 这里好坑 n表示n个顶点, 但输入只有n-1行 
      cin >> x >> w;
      while (w--) {
        cin >> y >> len;
        if (map[x-'A'+1][y-'A'+1] > len) map[x-'A'+1][y-'A'+1] = map[y-'A'+1][x-'A'+1] = len;
      }
    }
    int ans = prim(1);
    cout << ans  << "\n"; 
  }
  return 0;
}

内容概要:该论文聚焦于T2WI核磁共振图像超分辨率问题,提出了一种利用T1WI模态作为辅助信息的跨模态解决方案。其主要贡献包括:提出基于高频信息约束的网络框架,通过主干特征提取分支和高频结构先验建模分支结合Transformer模块和注意力机制有效重建高频细节;设计渐进式特征匹配融合框架,采用多阶段相似特征匹配算法提高匹配鲁棒性;引入模型量化技术降低推理资源需求。实验结果表明,该方法不仅提高了超分辨率性能,还保持了图像质量。 适合人群:从事医学图像处理、计算机视觉领域的研究人员和工程师,尤其是对核磁共振图像超分辨率感兴趣的学者和技术开发者。 使用场景及目标:①适用于需要提升T2WI核磁共振图像分辨率的应用场景;②目标是通过跨模态信息融合提高图像质量,解决传统单模态方法难以克服的高频细节丢失问题;③为临床诊断提供更高质量的影像资料,帮助医生更准确地识别病灶。 其他说明:论文不仅提供了详细的网络架构设计与实现代码,还深入探讨了跨模态噪声的本质、高频信息约束的实现方式以及渐进式特征匹配的具体过程。此外,作者还对模型进行了量化处理,使得该方法可以在资源受限环境下高效运行。阅读时应重点关注论文中提到的技术创新点及其背后的原理,理解如何通过跨模态信息融合提升图像重建效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值