Hie with the Pie POJ - 3311(wa)

本文探讨了一种算法,用于解决单一司机如何在有限站点内快速递送比萨并返回出发点的问题。通过状态压缩动态规划,寻找最优递送路径。

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

The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it means passing the same location(s) or the pizzeria more than once on the way. He has commissioned you to write a program to help him.

Input
Input will consist of multiple test cases. The first line will contain a single integer n indicating the number of orders to deliver, where 1 ≤ n ≤ 10. After this will be n + 1 lines each containing n + 1 integers indicating the times to travel between the pizzeria (numbered 0) and the n locations (numbers 1 to n). The jth value on the ith line indicates the time to go directly from location i to location j without visiting any other locations along the way. Note that there may be quicker ways to go from i to j via other locations, due to different speed limits, traffic lights, etc. Also, the time values may not be symmetric, i.e., the time to go directly from location i to j may not be the same as the time to go directly from location j to i. An input value of n = 0 will terminate input.

Output
For each test case, you should output a single number indicating the minimum time to deliver all of the pizzas and return to the pizzeria.

Sample Input
3
0 1 10 10
1 0 1 2
10 1 0 10
10 2 10 0
0
Sample Output
8
这题不知道为什么用搜索做的状态压缩dp有问题
问题代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include <iostream>
#include<cmath>
#include <string>
#define mod 9973
#define MAXN 100000000
using namespace std;

int d[13][13];
int dp[1<<12][12];
int n;
int rec(int s,int v)
{
    if(dp[s][v]!=-1)
        return dp[s][v];
    int res=MAXN;
    int s1=s^(1<<(n-v));
    for(int i=1;i<=n;i++)
    {
        if(s1&(1<<(n-i)))
        {
            res=min(res,rec(s1,i)+d[v][i]);
        }
    }
    return dp[s][v]=res;
}
int main()
{
   for(;;)
   {
       scanf("%d",&n);
       if(!n)break;
       for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
           scanf("%d",&d[i][j]);
        memset(dp,-1,sizeof(dp));

       for(int k=0;k<=n;k++)
        for(int i=0;i<=n;i++)
            for(int j=0;j<=n;j++)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);//各个点之间的最短距离

        for(int i=1;i<=n;i++)
            dp[1<<(n-i)][i]=d[0][i];//递归的边界

        int ans=rec((1<<n)-1,1)+d[1][0];
        for(int i=2;i<=n;i++)
            ans=min(ans,rec((1<<n)-1,i)+d[i][0]);//枚举走完所有点并且以i点结尾的店,并加上返回0点的距离
       printf("%d\n",ans);

    }
    return 0;
}
### HIE-FDTD 方法概述 混合隐式显式有限差分时域 (Hybrid Implicit Explicit Finite-Difference Time-Domain, HIE-FDTD) 是一种用于计算电磁场传播的技术,特别适用于处理具有高对比度材料特性的复杂结构。该方法通过引入隐式和显式的离散化方案来提高数值稳定性并减少计算资源消耗[^1]。 ### 数学模型与算法原理 HIE-FDTD 的核心在于将传统的 FDTD 显式更新公式与 Crank-Nicolson 隐式求解器相结合。对于电导率较高的区域采用隐式格式,在低损耗介质部分则继续沿用标准FDTD的显式迭代方式: \[ \frac{E^{n+1}-E^n}{\Delta t}=\mu^{-1}\left(\nabla\times H+\sigma E^{(n+1)+E^n}/2\right)\] 其中 \(E\) 表示电场强度矢量;\(H\) 代表磁场强度矢量;\(\mu,\epsilon,\sigma\) 分别对应磁导率、介电常数以及电导率参数[\^2]. ### 技术实现要点 为了有效实施 HIE-FDTD 算法,需注意以下几个方面: - **网格划分**: 对于不同性质(如金属/绝缘体界面)处应适当加密单元格尺寸; - **边界条件设置**: 可选用吸收边界条件(PML),以降低反射误差影响仿真精度; - **时间步长选取**: 应满足 Courant–Friedrichs–Lewy(CFL)稳定准则的同时尽可能大些以便加速收敛过程. ```matlab % 初始化参数 dx = dy = dz = 0.01; % 空间分辨率 dt = dx/(sqrt(mu*eps)*c); % 时间间隔遵循CFL条件限制 Nt = round(T/dt); % 总的时间步数 for n=1:Nt update_H_field(); % 更新半整时刻磁场分布 apply_implicit_scheme_to_conductive_regions(); % 处理传导区内的电场变化 explicit_update_E_field_outside_conductors(); % 直接推进自由空间中的电波演化 end ``` ### 实际应用场景举例 此技术广泛应用于微波工程领域内天线设计优化、高速互连建模分析等方面。例如,在研究印刷电路板上信号传输特性时,可以利用 HIE-FDTD 来模拟高频电流如何穿过多层基片,并评估由此产生的串扰效应等问题[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值