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 ...
随机推荐
- 第六篇 native 版本的Postman如何通过代理服务器录制Web及手机APP请求
第四篇主要介绍了chrome app版本的postman如何安装及如何录制Web脚本,比较简单. 但是chrome app 版本和native 版本相比,对应chrome app 版本官方已经放弃支持 ...
- Maven私库
<server> <id>releases</id> <username>admin</username> <password> ...
- 首次使用windows管理界面访问安装在UNIX或linux下的DP服务器时提示无权限访问的解决方法
用windwos GUI管理界面连接时提示无权限访问: 在/etc/opt/omni/server/users/userlist 添加一行: "" "*" &q ...
- R-CNN学习总结
R-CNN是一个比较早期的用于目标检测方法,但却十分经典,在此结合论文对这一方法做一个总结. (写给小白:通过下图简单理解图像分类,图像定位,目标检测和实例分割) R-CNN方法提出的背景: 1.近1 ...
- 4.openldap创建索引
1.索引的意义 提高对Openldap目录树的查询速度 提高性能 减轻对服务器的压力 2.搜索索引 ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn= ...
- ie6下,莫名被复制出一段文字解决
在IE6下使用浮动可能会出现文字重复的情况. 在IE6下,浮动层之间有注释文字的话,之前那个浮动层的内容文字就有可能遭遇一个“隐形”的复制,但是代码里查看文字可并没有多出来. 看个例子: HTML & ...
- mysql数据库工具
1.navicat12 中文版及破解 链接:https://pan.baidu.com/s/1TH8m6lduHJybUGhmjFPIAA 提取码:kwcd 2.旧版本mysql-front(连接可选 ...
- pandas中DataFrame的ix,loc,iloc索引方式的异同
pandas中DataFrame的ix,loc,iloc索引方式的异同 1.loc: 按照标签索引,范围包括start和end 2.iloc: 在位置上进行索引,不包括end 3.ix: 先在inde ...
- HDU 5428 The Factor 分解因式
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5428 The Factor Accepts: 101 Submissions: 811 Tim ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...