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 ...
随机推荐
- Android 测试 之adb shell
一.发送键盘事件: 命令格式1:adb shell input keyevent "value" 其中value以及对应的key code如下表所列: KeyEvent Value ...
- SQL Server临时表漫谈
SQL Server是微软的关系型数据库,对于刚入门的我是一个非常友好的开发工具.可视化界面的安装与操作,非常适合刚入门的我. 其实大家要找这方面的资料,在网上一搜一大堆,这里我就不赘述那些了,基本都 ...
- centos7.2部署docker-17.06.0-ce的bug:Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"\"".
现象: 操作系统:centos 7.2 kernel 3.10.0-327.el7.x86_64 mesos:1.3.0 docker:docker-17.06.0-ce 在做mesos验证时,通过m ...
- leetcode个人题解——#56 Merge Intervals
思路,先按照结构体中start进行排序,然后遍历比较前后项是否有重合. 第一次用到三参数形式的sort(),第三个参数的bool函数要写到类外才通过. /** * Definition for an ...
- PHP使用static关键字声明静态属性和静态方法
PHP使用static关键字声明静态属性和静态方法 在PHP中,通过static关键字修饰的成员属性和成员方法被称为静态属性和静态方法. 静态属性和静态方法不需要在被类实例化的情况下就可以直接使用. ...
- Echarts数据可视化全解
点击进入 Echarts数据可视化全解
- 20181120-8 Beta阶段第2周/共2周 Scrum立会报告+燃尽图 06
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2414 版本控制地址 [https://git.coding.net ...
- MathExam第二次作业(升级版)
MathExamLv2——林华伟 211506319 陈珍 211406263 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实 ...
- 《C》VS控制台应用
源(c)文件:主要是源码,包括程序入口,函数的实现 头(h)文件:主要是定义的函数声明 资源(rc)文件:程序中用到的辅助资源,比如位图,图标资源 解决VS2015安装后stdio.h ucrtd.l ...
- Iterable,Iterator和forEach
Iterable Interface Iterable<T> 方法: Iterator<T> iterator() Returns an iterator over a set ...