Truck History--poj1789

本文深入解析了TruckHistory问题背景及挑战,详细解释了如何通过最小生成树解决寻找最佳衍生方案的问题,并提供了算法实现的源代码。通过实例分析,读者能够清晰理解最小生成树在实际问题解决中的应用。

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

Truck History
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 21534 Accepted: 8379

Description

Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type was used but later other types were derived from it, then from the new types another types were derived, and so on. 

Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as 
1/Σ(to,td)d(to,td)

where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types. 
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan. 

Input

The input consists of several test cases. Each test case begins with a line containing the number of truck types, N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code (a string of seven lowercase letters). You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same. The input is terminated with zero at the place of number of truck types.

Output

For each test case, your program should output the text "The highest possible quality is 1/Q.", where 1/Q is the quality of the best derivation plan.

Sample Input

4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0

Sample Output

The highest possible quality is 1/3.



这题,我是没看懂,后来看的别人的翻译才自己做的!

 > 题意大概是这样的:用一个7位的string代表一个编号,两个编号之间的distance代表这两个编号之间不同字母的个数。一个编号只能由另一个编号“衍生”出来,代价是这两个编号之间相应的distance,现在要找出一个“衍生”方案,使得总代价最小,也就是distance之和最小。

> 例如有如下4个编号:

> aaaaaaa

> baaaaaa

> abaaaaa

> aabaaaa

> 显然的,第二,第三和第四编号分别从第一编号衍生出来的代价最小,因为第二,第三和第四编号分别与第一编号只有一个字母是不同的,相应的distance都是1,加起来是3。也就是最小代价为3。


显然,最小生成树!



 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 int per[2010],n;
 7 struct node
 8 {
 9     int b,e,w;
10 }s[2000500];//我开的挺大的,怕不够
11 bool cmp(node x,node y)
12 {
13     return x.w<y.w;
14 }
15 void init()
16 {
17     for(int i=0;i<=n;i++)
18     per[i]=i;
19 }
20 int find(int x)
21 {
22     int i=x,j;
23     while(x!=per[x])
24     x=per[x];
25     while(i!=x)//我压缩了路径踩过的,超时了好多次
26     {
27         j=per[i];
28         per[i]=x;
29         i=j;
30     }
31     return x;
32 }
33 bool join(int x,int y)
34 {
35     int fx=find(x);
36     int fy=find(y);
37     if(fx!=fy)
38     {
39         per[fx]=fy;
40         return true;
41     }
42     return false;
43 }
44 int main()
45 {
46     char map[2010][10];
47     while(scanf("%d",&n),n)
48     {
49         getchar();
50         init();
51         int i,j;
52         for(int i=0;i<n;i++)
53         scanf("%s",map[i]);
54         int k=0,sum=0,t;
55         for(i=0;i<n;i++)
56         {
57             for(j=i+1;j<n;j++)
58             {
59                 int cot=0;
60                 for(t=0;t<7;t++)
61                 {
62                     if(map[i][t]!=map[j][t])
63                     cot++;    
64                 }
65                 s[k].b=i;
66                 s[k].e=j;
67                 s[k].w=cot;
68                 k++;
69             }
70         }
71         sort(s,s+k,cmp);
72         for(i=0;i<k;i++)
73         {
74             if(join(s[i].b,s[i].e))
75             sum+=s[i].w;
76         }
77         printf("The highest possible quality is 1/%d.\n",sum);
78     }
79     return 0;
80 }

 

欢迎留言。

转载于:https://www.cnblogs.com/Eric-keke/p/4722103.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值