Codeforces 983C Elevator dp (看题解)
怎么今天写啥题都不会写啊, 我是傻了吗。。
把电梯里面四个人的目标点当作状态, 然后暴力转移。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int dp[][][][][][];
int n, a[N], b[N];
int cur = , lst = ; inline bool chkmin(int &a, int b) {
return a > b ? a = b, true : false;
} int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
memset(dp[cur], inf, sizeof(dp[cur]));
dp[cur][][][][][] = * n;
for(int i = ; i <= n; i++) {
swap(cur, lst);
memset(dp[cur], inf, sizeof(dp[cur]));
for(int c1 = ; c1 >= ; c1--) {
for(int c2 = ; c2 >= ; c2--) {
for(int c3 = ; c3 >= ; c3--) {
for(int c4 = ; c4 >= ; c4--) {
for(int f = ; f <= ; f++) {
int& ret = dp[lst][f][c1][c2][c3][c4];
if(ret >= inf) continue;
if(!c1 && i < n) {
chkmin(dp[cur][a[i + ]][b[i + ]][c2][c3][c4], ret + abs(f - a[i + ]));
} else if(c1) {
chkmin(dp[lst][c1][][c2][c3][c4], ret + abs(f - c1));
}
if(!c2 && i < n) {
chkmin(dp[cur][a[i + ]][c1][b[i + ]][c3][c4], ret + abs(f - a[i + ]));
} else if(c2) {
chkmin(dp[lst][c2][c1][][c3][c4], ret + abs(f - c2));
}
if(!c3 && i < n) {
chkmin(dp[cur][a[i + ]][c1][c2][b[i + ]][c4], ret + abs(f - a[i + ]));
} else if(c3) {
chkmin(dp[lst][c3][c1][c2][][c4], ret + abs(f - c3));
}
if(!c4 && i < n) {
chkmin(dp[cur][a[i + ]][c1][c2][c3][b[i + ]], ret + abs(f - a[i + ]));
} else if(c4) {
chkmin(dp[lst][c4][c1][c2][c3][], ret + abs(f - c4));
}
}
}
}
}
}
}
int ans = inf;
for(int i = ; i <= ; i++)
ans = min(ans, dp[lst][i][][][][]);
printf("%d\n", ans);
return ;
} /*
*/
Codeforces 983C Elevator dp (看题解)的更多相关文章
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces 865C Gotta Go Fast 二分 + 期望dp (看题解)
第一次看到这种骚东西, 期望还能二分的啊??? 因为存在重置的操作, 所以我们再dp的过程中有环存在. 为了消除环的影响, 我们二分dp[ 0 ][ 0 ]的值, 与通过dp得出的dp[ 0 ][ 0 ...
- Codeforces 513E2 Subarray Cuts dp (看题解)
我们肯定要一大一小间隔开来所以 把式子拆出来就是类似这样的形式 s1 - 2 * s2 + 2 * s3 + ...... + sn 然后把状态开成四个, 分别表示在顶部, 在底部, 在顶部到底部的中 ...
- Codeforces 442D Adam and Tree dp (看题解)
Adam and Tree 感觉非常巧妙的一题.. 如果对于一个已经建立完成的树, 那么我们可以用dp[ i ]表示染完 i 这棵子树, 并给从fa[ i ] -> i的条边也染色的最少颜色数. ...
- Codeforces 1101F Trucks and Cities dp (看题解)
Trucks and Cities 一个很显然的做法就是二分然后对于每个车贪心取check, 这肯定会TLE, 感觉会给人一种贪心去写的误导... 感觉有这个误导之后很难往dp那个方向靠.. dp[ ...
- Codeforces 596D Wilbur and Trees dp (看题解)
一直在考虑, 每一段的贡献, 没想到这个东西能直接dp..因为所有的h都是一样的. #include<bits/stdc++.h> #define LL long long #define ...
- Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)
Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...
- Codeforces 498B Name That Tune 概率dp (看题解)
Name That Tune 刚开始我用前缀积优化dp, 精度炸炸的. 我们可以用f[ i ][ j ] 来推出f[ i ][ j + 1 ], 记得加加减减仔细一些... #include<b ...
- Codeforces 269C Flawed Flow (看题解)
我好菜啊啊啊.. 循环以下操作 1.从队列中取出一个顶点, 把哪些没有用过的边全部用当前方向. 2.看有没有点的入度和 == 出度和, 如果有将当前的点加入队列. 现在有一个问题就是, 有没有可能队列 ...
随机推荐
- Java SE之Java工作原理
在Java中引入了虚拟机的概念,即在机器和编译程序之间加入了一层抽象的虚拟的机器.这台虚拟的机器在任何平台上都提供给编译程序一个的共同的接口.编译程序只需要面向虚拟机,生成虚拟机能够理解的代码,然后 ...
- sizeof strlen区别于联系
http://www.cnblogs.com/carekee/articles/1630789.html
- iptables学习笔记_____摘自朱双印个人日志 ____http://www.zsythink.net/
iptables为我们预先定义了四张表 raw.mangle.nat.filter filter表负责过滤:允许那些ip访问.拒绝那些ip访问.允许那些端口...是最常用的表 #查看表里面所有的规则i ...
- SVM实例及Matlab代码
******************************************************** ***数据集下载地址 :http://pan.baidu.com/s/1geb8CQf ...
- 用C++的 new 代替 C 的 malloc 进行内存分配
例子: (int*)malloc(100*sizeof(int)) 是先取得int类型的字节宽度,然后乘100计算后得到400,然后调用malloc,并将400传递给函数,分配400字节的内存空间,但 ...
- matplotlib 画图
matplotlib 画图 1. 画曲线图 Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...
- [转]Linux下的链接脚本基础
[转]http://linux.chinaunix.net/techdoc/beginner/2009/08/12/1129972.shtml 1. 前言 (1)每一个链接过程都由链接脚本(linke ...
- 关注网页的更新状况,了解最新的handsup 消息.
// 第一部分是网页截图和源码保存 // upon page load. var fs = require("fs"); var resourceWait = 300, maxRe ...
- dubbo系列三、架构介绍及各模块关系
一.整体设计 图例说明: 图中左边淡蓝背景的为服务消费方使用的接口,右边淡绿色背景的为服务提供方使用的接口,位于中轴线上的为双方都用到的接口. 图中从下至上分为十层,各层均为单向依赖,右边的黑色箭头代 ...
- Windows CreateFont:创建自己的字体
原文地址:http://blog.csdn.net/softn/article/details/51718347 前面无论是使用文本输出函数还是 static 控件,字体都是默认的,比较丑陋,我们完全 ...