link

试题分析

我们发现$dp(t,s1,s2,s3)$表示在$t$时刻$3$个人的位置。发现时间复杂度为$O(n \times L^3)$。不仅会$T$还会$MLE$,所以需要优化$dp$。我们发现当次$dp$合法时,肯定会有一项是到达的那个位置,所以可以优化掉一维。只需要把那个必须要经过的位置去掉,时间复杂度就变为$O(n \times L^2)$。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<climits>
using namespace std;
inline int read(){
int f=,ans=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){ans=ans*+c-'';c=getchar();}
return f*ans;
}
const int N=;
const int L=;
int dp[N][L][L],val[L][L],n,l,p[N],minn=INT_MAX;
bool judge(int x1,int x2,int x3){
return (x1!=x2)&&(x2!=x3)&&(x1!=x3);
}
int _min(int a,int b){ return a>b?b:a;}
int main(){
l=read();n=read();
for(int i=;i<=l;i++)
for(int j=;j<=l;j++) val[i][j]=read();
memset(dp,/,sizeof(dp));dp[][][]=,dp[][][]=;p[]=;
for(int t=;t<=n;t++){
p[t]=read();
for(int i=;i<=l;i++){
for(int j=;j<=l;j++){
/*val[i][p]*/
if(judge(p[t],p[t-],j)){
dp[t][p[t-]][j]=_min(dp[t][p[t-]][j],dp[t-][i][j]+val[i][p[t]]);
dp[t][j][p[t-]]=_min(dp[t][p[t-]][j],dp[t][j][p[t-]]);
}
/*val[j][p]*/
if(judge(p[t-],i,p[t])){
dp[t][p[t-]][i]=_min(dp[t][p[t-]][i],dp[t-][i][j]+val[j][p[t]]);
dp[t][i][p[t-]]=_min(dp[t][p[t-]][i],dp[t][i][p[t-]]);
}
/*val[p[t-1]][p]*/
if(judge(i,j,p[t])){
dp[t][i][j]=_min(dp[t][i][j],dp[t-][i][j]+val[p[t-]][p[t]]);
dp[t][j][i]=_min(dp[t][j][i],dp[t][i][j]);
} }
}
}
for(int i=;i<=l;i++)
for(int j=;j<=l;j++) {
if(!(i!=j&&i!=p[n]&&j!=p[n])) continue;
minn=min(minn,dp[n][i][j]);
}
printf("%d",minn);
}

Mobile Service的更多相关文章

  1. Unable to create Azure Mobile Service: Error 500

    I had to go into my existing azure sql database server and under the configuration tab select " ...

  2. 如何使用新浪微博账户进行应用登录验证(基于Windows Azure Mobile Service 集成登录验证)

    使用三方账号登录应用应该对大家来说已经不是什么新鲜事儿了,但是今天为什么还要在这里跟大家聊这个话题呢,原因很简单 Windows Azure Mobiles Service Authenticatio ...

  3. vs2015-Azure Mobile Service

    /App_Data /App_Start/ WebApiConfig.cs using System; using System.Collections.Generic; using System.C ...

  4. windows phone开发-windows azure mobile service使用入门

    在使用azure之前,我一直只能做本地app,或者使用第三方提供的api,尽管大多数情况下够用,但是仍不能随心所欲操纵数据,这种感觉不是特别好.于是在azure发布后,我就尝试使用azure来做为个人 ...

  5. CH5102 Mobile Service【线性dp】

    5102 Mobile Service 0x50「动态规划」例题 描述 一个公司有三个移动服务员,最初分别在位置1,2,3处.如果某个位置(用一个整数表示)有一个请求,那么公司必须指派某名员工赶到那个 ...

  6. CH5102 Mobile Service

    CH5102 Mobile Service 描述 一个公司有三个移动服务员,最初分别在位置1,2,3处.如果某个位置(用一个整数表示)有一个请求,那么公司必须指派某名员工赶到那个地方去.某一时刻只有一 ...

  7. CH 5102 Mobile Service(线性DP)

    CH 5102 Mobile Service \(solution:\) 这道题很容易想到DP,因为题目里已经说了要按顺序完成这些请求.所以我们可以线性DP,但是这一题的状态不是很好设,因为数据范围有 ...

  8. Windows Azure之Mobile Service

    我建个android app和Windows Azure的Mobile Service配合,以实现会员注册的功能,实际十分简单,微软家的东西真心好用 首先新建个Mobile Service New-& ...

  9. TYVJ1061 Mobile Service

    P1061 Mobile Service 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 一个公司有三个移动服务员.如果某个地方有一个请求,某个员工必须赶到那 ...

  10. Mobile Service更新和 Notification Hub 对Android的支持

    本周,我们要推出一些更新,使移动服务成为移动应用程序更强大.更灵活的后端,同时推出一个与移动服务或网站结合使用的免费 20MB SQL 数据库,并且将支持通过Notification Hub中的 GC ...

随机推荐

  1. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) E. Down or Right

    从(1,1,n,n)每次只变一个坐标,进行询问. 如果问到对角线有距离限制, 再从(1,1,n/2,n/2)询问到(n/2,n/2,n,n) 记住前半部分贪心忘上走,后本部分贪心往右走 因为最后的路线 ...

  2. Vue学习计划基础笔记(三)-class与style绑定,条件渲染和列表渲染

    Class与style绑定.条件渲染和列表渲染 目标: 熟练使用class与style绑定的多种方式 熟悉v-if与v-for的用法,以及v-if和v-for一起使用的注意事项 class与style ...

  3. 深圳第XX天

    今天早晨,面了一家小公司.先说结果吧,面过了.但是,总感觉太假了.面试中很多问题都没有回答上来.然后老板看了一下简历,问:期薪资多少?我想了想,说7000.啊,要不留下来看看?我答应了.不到十分钟,就 ...

  4. HPUX修改disk实例号--11.31only

    有时由于一些原因或者用户的要求,需要修改Disk的实例号,这里简单介绍如何手工进行修改. 在修改之前需要做一些准备工作,即先将stale状态的设备文件清理掉,具体步骤如下: 使用ioscan命令列出s ...

  5. 《Learning scikit-learn Machine Learning in Python》chapter1

    前言 由于实验原因,准备入坑 python 机器学习,而 python 机器学习常用的包就是 scikit-learn ,准备先了解一下这个工具.在这里搜了有 scikit-learn 关键字的书,找 ...

  6. Material Safety Data Sheet,MSDS - 化学品安全说明书

    化学品安全说明书(Material Safety Data Sheet)MSDS,国际上称作化学品安全信息卡,是化学品生产商和经销商按法律要求必须提供的化学品理化特性(如PH值,闪点,易燃度,反应活性 ...

  7. 调试和开发npm模块的方式

    ln -s(软连接) 假设my-project是运行npm模块的项目,vue-router是我们需要调试的npm模块 将vue-router下载到与my-project同级目录中. git clone ...

  8. B. Counting-out Rhyme(约瑟夫环)

    Description n children are standing in a circle and playing the counting-out game. Children are numb ...

  9. 软件工程第七周psp

    1.PSP表格 类别 任务 开始时间 结束时间 中断时间 delta时间 立会 汇报昨天的成绩,分配任务,部署计划 10月27日18:00 10月27日18:36 0 36分钟 准备工作 查阅有关资料 ...

  10. OpenCV学习笔记——图像平滑处理

    1.blur 归一化滤波器Blurs an image using the normalized box filter.C++: void blur(InputArray src, OutputArr ...