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的更多相关文章

  1. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. poj[2392]space elevator

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  3. Design Elevator

    From: https://discuss.leetcode.com/topic/89/write-elevator-program-using-event-driven-programming/9 ...

  4. 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 ...

  5. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]

    作业提交时间:10月9日上课前. Design and implement an Elevator Scheduler to aim for both correctness and performa ...

  6. POJ2392Space Elevator(贪心+背包)

    Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 De ...

  7. hdu 1008 Elevator

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The hig ...

  8. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  9. 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 ...

随机推荐

  1. 域名带与不带www的区别

    首先我们来说下为什么会产生带www与不带www的两种域名. 不带www的域名为顶级域名或一级域名,如qiankoo.com.带www的为二级域名,如www.qiankoo.com. 在购买域名时,域名 ...

  2. window.open()方法详解

    , 最基本的弹出窗口代码   window.open('page.html'); 2, 经过设置后的弹出窗口   window.open('page.html', 'newwindow', 'heig ...

  3. Don't let anyone tell you different.

    Don't let anyone tell you different.不要让任何人否定你的与众不同.

  4. 使用css写三角箭头

    .right-arrow{ width:6px; height:6px; align-self: center; border-right:1px solid #2ac795; border-left ...

  5. LeetCode Valid Anagram (简单题)

    题意: 给出两个字符串s和t,判断串t是否为s打乱后的串. 思路: 如果返回的是true,则两个串的长度必定相等,所有字符出现的次数一样.那么可以统计26个字母的次数来解决,复杂度O(n).也可以排序 ...

  6. 如何处理SAP HANA Web-Based Development Workbench的403 Forbidden错误

    打开SAP云平台上的SAP HANA Web-Based Development Workbench超链接: 遇到错误信息:403 - Forbidden - The server refused t ...

  7. Android(java)学习笔记84:SQLiteDatabase的query方法参数

    1. SQLiteDatabase的query方法: public Cursor query (boolean distinct, String table, String[] columns, St ...

  8. 2018.6.1 oracle数据库乱码问题

    执行select * from v$controlfile;为什么结果是未选定行? 显示连接了但是select * from dba_data_files; 显示中文乱码: shutdown star ...

  9. python剑指offer系列二叉树中和为某一值的路径

    题目描述 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长度大 ...

  10. Angular2的笔记

    1.如果启动项目的时候出现下列黄色的警告说明电脑安装的全局cli和项目中使用的cli版本不一致,不过不影响使用,按它的提示执行 ng set --global warnings.versionMism ...