Truck History Poj 1789(Prim)

本文深入探讨了信息技术领域的核心技术和应用,包括但不限于前端开发、后端开发、移动开发、游戏开发、大数据开发等细分领域。从技术原理、实践案例到最新趋势,全方位解析信息技术在现代社会发展中的重要作用。
Truck History
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 21311 Accepted: 8277

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.



感觉这道题难就难在建图上。我居然又将 Map[i][j]=Map[j][i]=*写成了Map[i][j]=*,在经过大脑0.1秒的思考并不是一定是先输入的是衍生根Q Q。


#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define INF 0x3f3f3f3f

using namespace std;

char s[2001][8];
int Map[2001][2001],ans,vis[2001],dis[2001],n,z;
void prim()
{
    int i,j,k,pos,ma;
    memset(vis,0,sizeof(vis));
    for(i=1; i<n; i++)
        dis[i]=Map[0][i];
    vis[0]=1;
    for(i=0; i<n-1; i++)
    {
        ma=INF;
        for(j=1; j<n; j++)
        {
            if(dis[j]<ma&&!vis[j])
            {
                ma=dis[j];
                pos=j;
            }
        }
        z+=ma;
        vis[pos]=1;
        for(j=1; j<n; j++)
        {
            if( dis[ j ]>Map[pos][j] &&!vis[j])
            {
                dis[j]=Map[pos][j];
            }
        }
    }
    printf("The highest possible quality is 1/%d.\n",z);
}
int main()
{
    int i,j,k,m,mi;
    ios::sync_with_stdio(false);
    while(cin>>n&&n)
    {
        z=0;
        for(i=0; i<n; i++)
            cin>>s[i];
        memset(Map,0,sizeof(Map));
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
            if(i!=j)
               Map[j][i]=Map[i][j]=INF;
            else
               Map[i][j]=0;
        }
        for(i=0; i<n; i++)
        {
            ans=0;
            for(j=0; j<n; j++)
            {
                ans=0;
                for(k=0; k<7; k++)
                {
                    if(s[i][k]!=s[j][k])
                    {
                        ans++;
                    }
                }
                if(Map[i][j]>ans)
                {
                    Map[i][j]=ans;
                    Map[j][i]=ans;
                }
                //    cout<<Map[i][j]<<endl;
            }
        }
        prim();
    }
    return 0;
}




基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,并提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,并通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论分析与仿真验证相结合。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值