首页 > 其他分享 >SP703 SERVICE - Mobile Service

SP703 SERVICE - Mobile Service

时间:2022-11-09 05:11:07浏览次数:55  
标签:ch Service SERVICE Mobile SP703 getchar

SP703 SERVICE - Mobile Service - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

容易想到状态 \(f(i, x, y, z)\) 表示完成了前 \(i\) 个请求,三个员工分别位于 \(x\),\(y\),\(z\) 时,当前最小花费。

发现状态规模达到 \(nL^3\),不能接受。考虑完成前 \(i\) 个请求后一定有一个员工位于 \(p[i]\),因此有一位员工位置信息是冗余的。

更换定义,\(f(i, x, y)\) 表示完成了前 \(i\) 个请求,三个员工分别位于 \(p[i]\),\(x\),\(y\) 时的最小花费。

初始时 \(f\) 应该均置为 \(+\infty\),\(f(0, 2, 3) = 0\),\(p[0] = 1\)。

时间复杂度 \(\mathcal{O}(nL^2)\)。

/*
 * @Author: crab-in-the-northeast 
 * @Date: 2022-11-09 04:32:07 
 * @Last Modified by: crab-in-the-northeast
 * @Last Modified time: 2022-11-09 04:53:57
 */
#include <bits/stdc++.h>
inline int read() {
    int x = 0;
    bool f = true;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-')
            f = false;
    for (; isdigit(ch); ch = getchar())
        x = (x << 1) + (x << 3) + ch - '0';
    return f ? x : (~(x - 1));
}
inline bool gmi(int &a, int b) {
    return b < a ? a = b, true : false;
}

const int maxl = 205;
const int maxn = 1005;

int c[maxl][maxl];
int p[maxn];
int f[maxn][maxl][maxl];

int main() {
    int T = read();
    while (T--) {
        int l = read(), n = read();
        std :: memset(f, 0x3f, sizeof(f));
        for (int i = 1; i <= l; ++i)
            for (int j = 1; j <= l; ++j)
                c[i][j] = read();
        for (int i = 1; i <= n; ++i)
            p[i] = read();
        
        p[0] = 1;
        f[0][2][3] = 0;
        for (int i = 0; i <= n; ++i) {
            for (int x = 1; x <= l; ++x) {
                for (int y = 1; y <= l; ++y) {
                    int z = p[i], t = p[i + 1];
                    int fn = f[i][x][y];
                    if (x == y || y == z || x == z)
                        continue;
                    if (x != t && y != t)
                        gmi(f[i + 1][x][y], fn + c[z][t]);
                    if (x != t && z != t)
                        gmi(f[i + 1][x][z], fn + c[y][t]);
                    if (y != t && z != t)
                        gmi(f[i + 1][y][z], fn + c[x][t]);
                }
            }
        }

        int ans = INT_MAX;
        for (int x = 1; x <= l; ++x)
            for (int y = 1; y <= l; ++y)
                if (x != y && x != p[n] && y != p[n])
                    gmi(ans, f[n][x][y]);
        
        printf("%d\n", ans);
    }
    return 0;
}

标签:ch,Service,SERVICE,Mobile,SP703,getchar
From: https://www.cnblogs.com/crab-in-the-northeast/p/sp703.html

相关文章

  • Kubernetes Service 笔记
    ServiceK8SService可以简单理解为逻辑上的一组Pod。一种可以访问Pod的策略,其他Pod可以通过这个Service访问到这个Service代理的Pod。相对于Pod而言,它会有一个固定的名称......
  • 数据源开发步骤; 数据源(连接池)的作用; IOC与DI的理解; 怎么把UserDao注入到UserService内
    数据源开发步骤1、导入数据源的坐标和数据库驱动坐标2、创建数据源对象3、设置数据源的基本连接数据4、使用数据源获取连接资源和归还连接资源数据源(连接池)的作用1、提高程......
  • 【Azure 应用服务】App Service的运行状况检查功能失效,一直提示"实例运行不正常"
    问题描述为AppService配置了健康检查,单独访问HealthCheckPath的路径,返回代码为200。但为什么在AppService的页面上,一直提示“实例运行不正常”呢? 问题解答通过查......
  • dotnet Core 在linux 下设置成Service
    1、新建.service文件cd/etc/systemd/system//进入改目录touchCore.service//新建Core服务文件viCore.service//编辑2、插入下面代码注意自己的服务名,以及项......
  • servicemesh及istio
    ServiceMesh以及Sidecar在介绍ServiceMesh概念之前,我们先来了解一下Sidecar。Sidecar是以第一次世界大战时活跃在战场上的军用边斗车命名(也是我们在抗日神剧中最常见的道......
  • Kubernetes K8S之Service服务详解与示例
    主机配置规划Service概述KubernetesService定义了这样一种抽象:逻辑上的一组Pod,一种可以访问它们的策略——通常被称为微服务。这一组Pod能够被Service访问到,通常是......
  • Filebeat启动失败,filebeat.service holdoff time over
    systemctlstatusfilebeat●filebeat.service-FilebeatsendslogfilestoLogstashordirectlytoElasticsearch.Loaded:loaded(/usr/lib/systemd/system/f......
  • Service Account
    在kubernetes中,有两种类型的账号,用户账号和服务账号;用户账号被用户所使用,服务账号被机器所使用;用户账号能够被管理员用作管理集群,或被开发人员用来在集群中部署应用;服......
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:AliPay组件
    本文简述在如何在Smobiler中调用支付宝支付。Step1.新建一个窗体,并在窗体中拖入Button,Label,AliPay等控件,布局如下:Step2.代码在窗体中声明变量//订单编号......
  • Android的Service作用和使用方法
    首先Service是干嘛的就是你Activity,finish之后你创建的Service还不会死,注意关闭软件这里是finish就是返回操作,不是清理后台,这时候你可以让用户干别的,你的软件依然可以......