NEFU 655 Trip(DP)

旅行计划:最小化时间到达目的地

Trip

Time Limit 1000ms

Memory Limit 65536K

description

  Xiao wang has a new car, so he wants to have a trip from his home to hefei, however, there is no road from his house directly to Hefei, so he has to go through a number of cities to get to hefei, his car takes one unit of time driving a unit distance at first, but his car will be slow after every city that he pass, so he will take one more unit of time to take a unit of distance after every city (that is, if he has passed k cities, then he needs k units of time to take a unit of distance, we think his home is the first city), can you tell him how to spend the least time to reach Hefei?
							

input

  The first line contains two numbers n and m (0 < n ≤ 200, 0 < m < n×(n-1)/2 ), n is the number of city, 1 is xiaowang's home, n is hefei, m is the number of road, bi-directional edge, then the following m line contains 3 numbers x, y, z, means there is a road from x to y, the distance is z.(You can make sure that there is always a path exist between his home ande hefei).
							

output

  The least time xiao wang must use from his home to hefei.
							

sample_input

5 6
1 2 1
1 4 5
2 3 2
3 5 1
4 5 1
2 4 2
							

sample_output

7
							

hint


								
							

source


思路:dp[x][y]从起始点能经过y个城市到达x城市的最优值

g[a][b]为城市a到城市b的距离

dp[x][y]=min(dp[k][y-1]+y*g[k][x])

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int mm=210;
const long long oo=1e18;
long long g[mm][mm];
long long dp[mm][mm];
int n,m;
int main()
{ int a,b,c;
  while(cin>>n>>m)
  { memset(g,-1,sizeof(g));
      for(int i=0;i<=n;++i)
      for(int j=0;j<=n;++j)
      dp[i][j]=oo;
    for(int i=0;i<m;++i)
    {scanf("%d%d%d",&a,&b,&c);
     g[a][b]=g[b][a]=c;
    }
    dp[1][0]=0;
    for(int i=1;i<=n;++i)
    {
      for(int j=1;j<=n;++j)
      {
        for(long long k=1;k<=n;++k)
          if(g[i][j]!=-1)
        dp[j][k]=min(dp[j][k],dp[i][k-1]+k*g[i][j]);
      }
    }
    long long ans=oo;
    for(int i=1;i<=n;++i)
      ans=min(ans,dp[n][i]);
      cout<<ans<<"\n";
  }
}




### 关于东北林业大学 (NEFU) 数据库及相关项目的资料 #### 1. NEFU 的背景介绍 东北林业大学(Northeast Forestry University, NEFU)作为一所具有鲜明林科特色的高等院校,在信息技术领域也有一定的研究基础和发展方向。该校不仅注重传统林业科学的研究,还积极将现代技术应用于森林资源管理、生态环境保护等领域[^1]。 #### 2. NEFU 数据库相关实验与教学 在 NEFU 的计算机科学与技术学院以及信息管理等相关专业的课程设置中,数据库原理及其应用是一个重要的组成部分。例如,在《数据库系统》课程的教学过程中,学生会通过实际操作 SQL 查询语句来掌握数据检索技巧。具体到实验环节,可能会涉及如下内容: - **查询所有学生都选修的课程名称** 这一需求可以通过转换逻辑表达式实现。由于 SQL 中不存在直接支持全称量词的操作符,因此可以采用否定的方式将其转化为存在量词的形式。即 `(∀x)P(x)` 可以被改写为 `¬(∃x ¬P(x))`。基于此理论,下面提供了一个可能的解决方案: ```sql SELECT cname FROM course c WHERE NOT EXISTS ( SELECT * FROM student s WHERE NOT EXISTS ( SELECT * FROM sc WHERE sc.sid = s.sid AND sc.cid = c.cid ) ); ``` 此处假设表结构定义如下: - 学生表 (`student`):包含字段 `sid`(学号), `sname`(姓名); - 课程表 (`course`):包含字段 `cid`(课程编号),`cname`(课程名); - 成绩表 (`sc`):记录学生的选课情况,关联字段分别为 `sid`, `cid`. 以上代码片段展示了如何利用嵌套子查询完成复杂条件下的筛选任务[^2]。 #### 3. 实际案例分析 —— 林业信息化建设项目 针对 NEFU 特有的学科优势,其参与开发的一些典型项目包括但不限于以下几个方面: - **智慧林业管理系统**:该项目旨在构建一套完整的数字化平台用于监测森林生长状况、病虫害防治效果评估等方面的工作。它依赖强大的后台数据库存储海量地理空间数据,并借助 GIS 技术呈现直观的地图界面供决策者参考。 - **碳汇计量模型优化工具包**:为了响应全球气候变化议题,研究人员设计了一款专门用来估算特定区域内植被吸收二氧化碳能力的应用程序。该软件内部集成了复杂的算法计算过程,同时需要连接外部气象站点获取实时环境参数输入值以便提高预测精度。 这些实例充分体现了 NEFU 将专业知识融入 IT 解决方案的能力水平。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值