cf984e Elevator
ref我好菜啊
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int n, u[2005], v[2005], f[2005][11][11][11][11];
int dis(int x, int y){
return abs(x-y);
}
int dfs(int i, int cur, int a, int b, int c){
if(f[i][cur][a][b][c]!=-1) return f[i][cur][a][b][c];
int re = 0x3f3f3f3f;
if(i>n){
if(!a && !b && !c) return 0;
if(a) re = min(re, dfs(i, a, 0, b, c)+dis(cur,a)+1);
if(b) re = min(re, dfs(i, b, a, 0, c)+dis(cur,b)+1);
if(c) re = min(re, dfs(i, c, a, b, 0)+dis(cur,c)+1);
f[i][cur][a][b][c] = re;
return re;
}
if(a) re = min(re, dfs(i, a, 0, b, c)+dis(cur,a)+1);
if(b) re = min(re, dfs(i, b, a, 0, c)+dis(cur,b)+1);
if(c) re = min(re, dfs(i, c, a, b, 0)+dis(cur,c)+1);
if(a && b && c){
re = min(re, dfs(i+1, v[i], a, b, c)+dis(cur,u[i])+dis(u[i],v[i])+2);
re = min(re, dfs(i+1, a, v[i], b, c)+dis(cur,u[i])+dis(u[i],a)+2);
re = min(re, dfs(i+1, b, a, v[i], c)+dis(cur,u[i])+dis(u[i],b)+2);
re = min(re, dfs(i+1, c, a, b, v[i])+dis(cur,u[i])+dis(u[i],c)+2);
}
else{
if(!a) re = min(re, dfs(i+1, u[i], v[i], b, c)+dis(cur,u[i])+1);
else if(!b) re = min(re, dfs(i+1, u[i], a, v[i], c)+dis(cur,u[i])+1);
else re = min(re, dfs(i+1, u[i], a, b, v[i])+dis(cur,u[i])+1);
}
f[i][cur][a][b][c] = re;
return re;
}
int main(){
cin>>n;
for(int i=1; i<=n; i++)
scanf("%d %d", &u[i], &v[i]);
memset(f, -1, sizeof(f));
cout<<dfs(1, 1, 0, 0, 0)<<endl;
return 0;
}
cf984e Elevator的更多相关文章
- HDOJ 1008. Elevator 简单模拟水题
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- poj[2392]space elevator
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- Design Elevator
From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9 ...
- PAT (Advanced Level) Practise:1008. Elevator
[题目链接] The highest building in our city has only one elevator. A request list is made up with N posi ...
- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]
作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...
- POJ2392Space Elevator(贪心+背包)
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9970 Accepted: 4738 De ...
- hdu 1008 Elevator
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description The hig ...
- 【ACM】HDU1008 Elevator 新手题前后不同的代码版本
[前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...
- Elevator 分类: HDU 2015-06-19 21:52 13人阅读 评论(0) 收藏
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
随机推荐
- java.lang.ClassNotFoundException:org/apache/commons/collections/CursorableLinkedList
明明有 commons-collections.jar 将jar包复制到Tomcat的WEB-INF/lib下就可以了...
- weblogic 忘记控制台账号密码 进行重新设置
第一步:首先要关闭weblogic服务. 第二步:对一些重要的文件进行备份: 1. 为了保证操作安全,备份%DOMAIN_HOME%/security/DefaultAuthenticatorInit ...
- LeetCode 4Sum 4个数之和
题意:这是继2sum和3sum之后的4sum,同理,也是找到所有4个元素序列,满足他们之和为target.以vector<vector<int>>来返回,也就是二维的,列长为4 ...
- ubuntu 自动启动程序
首先打开终端ctrl + alt + t sudo -i 输入密码:ubuntu chmod 777 /etc/rc.local 打开 vi /etc/rc.local 按 i 键进入输入 ...
- IP地址与数字地址相互转换
/// <summary> /// IP地址转换成数字 /// </summary> /// <param name="addr">IP地址&l ...
- C语言异常处理编程的三个境界
http://blog.csdn.net/treefish2012/article/details/17466487 这是上一次看完Herb Sutter的<Exceptional C++> ...
- 将数据库数据添加到ListView控件中
实现效果: 知识运用: ListView控件中的Items集合的Clear方法 //从listView控件的数据项集合中移除所有数据项 补充:可以使用Remove或RemoveAt方法从集合中移除单个 ...
- .NET利用RFC连接SAP,查询、读取SAP数据
为黄朴整理!!!!!!!!!!!!!!!!! 在NuGet 添加 sapnco 一个简单的SAPCommand,方法 GetDataTableFromRFCTable 复制于 https://www. ...
- 洛谷P1049装箱问题
一句话刚刚的题会了,这题能不会么. #include<bits/stdc++.h> using namespace std; int main(){ int n,m; cin>> ...
- 洛谷P3374树状数组1
下有彩蛋(from https://www.cnblogs.com/wuwangchuxin0924/p/5921130.html)树状数组的blog写的最好的是这位//https://www.cnb ...