hdu4571 Travel in time

本文介绍了一个基于动态规划的旅行时间优化算法,旨在帮助旅行者在有限时间内选择景点以获得最大满意度。通过处理复杂的路径和时间限制条件,该算法能够有效地找到最优解。

Travel in time

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 160    Accepted Submission(s): 31


Problem Description
  Bob gets tired of playing games, leaves Alice, and travels to Changsha alone. Yuelu Mountain, Orange Island, Window of the World, the Provincial Museum etc...are scenic spots Bob wants to visit. However, his time is very limited, he can’t visit them all.
  Assuming that there are N scenic spots in Changsha, Bob defines a satisfaction value Si to each spot. If he visits this spot, his total satisfaction value will plus Si. Bob hopes that within the limited time T, he can start at spot S, visit some spots selectively, and finally stop at spot E, so that the total satisfaction value can be as large as possible. It's obvious that visiting the spot will also cost some time, suppose that it takes C i units of time to visit spot i ( 0 <= i < N ).
  Always remember, Bob can choose to pass by a spot without visiting it (including S and E), maybe he just want to walk shorter distance for saving time.
  Bob also has a special need which is that he will only visit the spot whose satisfaction value is strictly larger than that of which he visited last time. For example, if he has visited a spot whose satisfaction value is 50, he would only visit spot whose satisfaction value is 51 or more then. The paths between the spots are bi-directional, of course.
 

Input
  The first line is an integer W, which is the number of testing cases, and the W sets of data are following.
  The first line of each test data contains five integers: N M T S E. N represents the number of spots, 1 < N < 100; M represents the number of paths, 0 < M < 1000; T represents the time limitation, 0 < T <= 300; S means the spot Bob starts from. E indicates the end spot. (0 <= S, E < N)
  The second line of the test data contains N integers C i ( 0 <= C i <= T ), which means the cost of time if Bob visits the spot i.
  The third line also has N integers, which means the satisfaction value Si that can be obtained by visiting the spot i ( 0 <= S i < 100 ).
  The next M lines, each line contains three integers u v L, means there is a bi-directional path between spot u and v and it takes L units of time to walk from u to v or from v to u. (0 <= u, v < N, 0 <= L <= T)
 

Output
  Output case number in the first line (formatted as the sample output).
  The second line contains an integer, which is the greatest satisfaction value.
If Bob can’t reach spot E in T units of time, you should output just a “0” (without quotation marks).
 

Sample Input
  
1 4 4 22 0 3 1 1 1 1 5 7 9 12 0 1 10 1 3 10 0 2 10 2 3 10
 

Sample Output
  
Case #1: 21
 

Source
 

Recommend
zhoujiaqi2010

水dp,就是处理的时候复杂一点而已。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

typedef struct
{
    int c,s,num;
}Point;

int map[105][105];
Point a[105];
int hash[105];
int dp[105][305];

bool cmp(Point x,Point y)
{
    if (x.s!=y.s) return x.s<y.s;
    return x.num<y.num;
}

int main()
{
    int i,j,n,m,t,s,x,y,z,ans,e,k,T,cnt=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d%d",&n,&m,&t,&s,&e);
        for (i=0;i<n;i++)
        {
            scanf("%d",&a[i].c);
        }
        for (i=0;i<n;i++)
        {
            scanf("%d",&a[i].s);
            a[i].num=i;
        }
        sort(a,a+n,cmp);
        for (i=0;i<n;i++)
        {
            hash[a[i].num]=i;
        }
        s=hash[s];
        e=hash[e];
        for (i=0;i<n;i++)
        {
            for (j=0;j<n;j++)
            {
                if (i==j) map[i][j]=0;
                else map[i][j]=100000000;
            }
        }
        for (i=0;i<m;i++)
        {
            scanf("%d%d%d",&x,&y,&z);
            x=hash[x];
            y=hash[y];
            map[x][y]=min(map[x][y],z);
            map[y][x]=min(map[y][x],z);
        }
        for (k=0;k<n;k++)
        {
            for (i=0;i<n;i++)
            {
                for (j=0;j<n;j++)
                {
                    map[i][j]=min(map[i][k]+map[k][j],map[i][j]);
                }
            }
        }
        printf("Case #%d:\n",cnt++);
        memset(dp,-1,sizeof(dp));
        for (i=0;i<n;i++)
        {
            for (j=a[i].c+map[i][s];j<=t;j++)
            {
                dp[i][j]=a[i].s;
            }
        }
        for (i=0;i<n;i++)
        {
            for (j=0;j<i;j++)
            {
                if (a[j].s==a[i].s) break;
                for (k=0;k<=t;k++)
                {
                    if (k<a[i].c+map[i][j]) continue;
                    if (dp[j][k-a[i].c-map[i][j]]==-1) continue;
                    dp[i][k]=max(dp[i][k],dp[j][k-a[i].c-map[i][j]]+a[i].s);
                }
            }
        }
        ans=0;
        for (i=0;i<n;i++)
        {
            for (j=0;j<=t;j++)
            {
                if (j+map[i][e]>t) break;
                ans=max(ans,dp[i][j]);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


内容概要:本文围绕列车-轨道-桥梁交互仿真研究,基于Matlab平台构建数值模型,系统分析列车运行过程中轨道与桥梁结构间的动态相互作用机制。研究涵盖多体动力学建模、耦合系统运动方程求解、边界条件设定及仿真结果可视化等关键环节,重点揭示高速行车条件下基础设施的振动传递规律与力学响应特征。该仿真方法可有效评估结构安全性、舒适性指标及疲劳寿命,为轨道交通工程的设计优化与运维管理提供理论支撑和技术路径。文中配套提供了完整的Matlab代码实现方案及操作说明,便于用户复现、验证和拓展相关研究。; 适合人群:具备Matlab编程基础和结构动力学、车辆动力学等相关专业知识的研究生、科研人员及从事铁路工程、桥梁工程与交通系统安全评估的工程技术人才,尤其适合开展轨道交通耦合振动课题的研究者。; 使用场景及目标:①用于高校与科研机构进行列车-轨道-桥梁耦合系统动力学特性的教学演示与科学研究;②支撑高速铁路桥梁的设计优化、运营安全性评估与减振降噪方案验证;③为复杂交通基础设施的多物理场耦合仿真提供建模思路与代码参考。; 阅读建议:建议读者结合所提供的Matlab代码逐模块深入研读,重点关注系统建模假设、质量-刚度-阻尼矩阵构建方法及数值积分算法的实现细节,同时可通过调整参数进行敏感性分析,进一步掌握仿真模型的适用范围与优化方向。
内容概要:本文系统研究了非线性薛定谔方程的物理信息神经网络(PINN)求解方法,提出一种将物理规律嵌入深度学习模型的科学计算新范式。通过构建全连接神经网络架构,将非线性薛定谔方程及其初始/边界条件作为损失函数的核心组成部分,实现了在无须大量标注数据的前提下对复值偏微分方程的高精度数值求解。该方法充分利用自动微分技术精确计算方程残差,有效融合了数据驱动与模型驱动的优势,在光学孤子传播、量子系统演化等典型场景中展现出优异的逼近能力与泛化性能。文中配套提供了完整的Python实现代码,涵盖网络搭建、损失定义、训练优化与结果可视化全流程。; 适合人群:具备Python编程能力与深度学习基础知识,熟悉偏微分方程理论及科学计算的理工科研究生、科研人员,以及从事光学、量子物理、流体力学等领域建模与仿真的工程技术人员。; 使用场景及目标:① 掌握PINN方法的基本原理与实现技巧;② 学习如何将复杂物理方程转化为可训练的神经网络损失项;③ 应用于非线性光学、玻色-爱因斯坦凝聚、水波动力学等问题的仿真与预测;④ 为相关科研课题提供可复现的算法原型与代码参考。; 阅读建议:建议读者结合所提供的Python代码进行动手实践,重点理解神经网络对微分算子的近似机制、损失函数的多任务加权策略以及训练过程中的超参数调优方法,进而可迁移至其他非线性偏微分方程的求解任务,拓展其在交叉学科中的应用边界。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值