Mobile Service
试题分析
我们发现$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的更多相关文章
- 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 " ...
- 如何使用新浪微博账户进行应用登录验证(基于Windows Azure Mobile Service 集成登录验证)
使用三方账号登录应用应该对大家来说已经不是什么新鲜事儿了,但是今天为什么还要在这里跟大家聊这个话题呢,原因很简单 Windows Azure Mobiles Service Authenticatio ...
- vs2015-Azure Mobile Service
/App_Data /App_Start/ WebApiConfig.cs using System; using System.Collections.Generic; using System.C ...
- windows phone开发-windows azure mobile service使用入门
在使用azure之前,我一直只能做本地app,或者使用第三方提供的api,尽管大多数情况下够用,但是仍不能随心所欲操纵数据,这种感觉不是特别好.于是在azure发布后,我就尝试使用azure来做为个人 ...
- CH5102 Mobile Service【线性dp】
5102 Mobile Service 0x50「动态规划」例题 描述 一个公司有三个移动服务员,最初分别在位置1,2,3处.如果某个位置(用一个整数表示)有一个请求,那么公司必须指派某名员工赶到那个 ...
- CH5102 Mobile Service
CH5102 Mobile Service 描述 一个公司有三个移动服务员,最初分别在位置1,2,3处.如果某个位置(用一个整数表示)有一个请求,那么公司必须指派某名员工赶到那个地方去.某一时刻只有一 ...
- CH 5102 Mobile Service(线性DP)
CH 5102 Mobile Service \(solution:\) 这道题很容易想到DP,因为题目里已经说了要按顺序完成这些请求.所以我们可以线性DP,但是这一题的状态不是很好设,因为数据范围有 ...
- Windows Azure之Mobile Service
我建个android app和Windows Azure的Mobile Service配合,以实现会员注册的功能,实际十分简单,微软家的东西真心好用 首先新建个Mobile Service New-& ...
- TYVJ1061 Mobile Service
P1061 Mobile Service 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 一个公司有三个移动服务员.如果某个地方有一个请求,某个员工必须赶到那 ...
- Mobile Service更新和 Notification Hub 对Android的支持
本周,我们要推出一些更新,使移动服务成为移动应用程序更强大.更灵活的后端,同时推出一个与移动服务或网站结合使用的免费 20MB SQL 数据库,并且将支持通过Notification Hub中的 GC ...
随机推荐
- JMeter学习笔记(二) 一些实际应用的基础操作
我在CSDN上面找到一位大师整理的jmeter性能测试基础,分享到这里继续学习 https://blog.csdn.net/u011541946/article/category/6893578/1
- 在intelij IDEA中添加对jetBrick文件的识别
在intelij IDEA中添加对jetBrick文件的识别 打开setting, 搜索File Types, 在Recognized File Types窗口找到Java Server Page或者 ...
- Longge's problem(欧拉函数应用)
Description Longge is good at mathematics and he likes to think about hard mathematical problems whi ...
- 20172321 2018-2019《Java软件结构与数据结构》第三周学习总结
教材学习内容总结 第五章 5.1概述 队列是一种线性集合,其元素从一端加入,从另一端删除:队列的处理方式是先进先出(First in First out). 与栈的比较(LIFO) 栈是一端操作,先进 ...
- 各团队对《t铁大导航》评价及我组回复
组名 对我们组的建议 我组回复 (1)跑男 你们的导航前期要做到什么样的程度呢?其实我一直是很期待你们完成时我能够用你们的导航来感受一下咱们铁大校园风情.你们用了数据结构算法来找最短路径,那你们能不能 ...
- springboot+vue+element:echarts开发遇见问题---后端sql(三)
<select id="getSumRequestRankingCount" parameterType="java.lang.String" resul ...
- 第5章 首次登录与在线求助man page
首次登录系统 centos默认图像界面为GNOME. Linux默认情况下会提供6个Terminal来让用户登录,切换方式为ctrl+alt+[F1-F6],系统将这六个操作界面命名为tty1-tty ...
- 团队项目-BUG排查-ADT工程 To Android Studio 一整天的排查日记
4-22 10:44至4-23 0:45 ①打开Eclipse从Github上Clone MathsApp到本机,报错'Unable to resolve target'android-19' ②尝试 ...
- PHP《将画布(canvas)图像保存成本地图片的方法》
用PHP将网页上的Canvas图像保存到服务器上的方法 2014年6月27日 歪脖骇客 发表回复 8 在几年前HTML5还没有流行的时候,我们的项目经理曾经向我提出这样一个需求:让项目评审专家们在评审 ...
- artdialog对话框 三种样式 网址:http://www.planeart.cn/demo/artDialog/_doc/labs.html
摇头效果 类似与wordpress登录失败后登录框可爱的左右晃动效果 // 2011-07-17 更新 artDialog.fn.shake = function (){ var style = th ...