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.看有没有点的入度和 == 出度和, 如果有将当前的点加入队列. 现在有一个问题就是, 有没有可能队列 ...
随机推荐
- bzoj4802 欧拉函数(附Millar-Rabin和Pollard-Rho讲解)
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4802 [题解] 参考:http://www.matrix67.com/blog/archiv ...
- QLabel-标签控件的应用
label = QLabel('我是李明') #创建标签控件对象.参数:标签中要显示的文本 label.setText('我是明明') 修改标签控件显示的文本 self.label.text() 返回 ...
- MySQL事务隔离级别以及验证
事务的并发执行,容易出现的几个现象 -------------------------- 1.脏读 读未提交,一个事务读取了另外一个事务改写还没有提交的数据,如果另外一个 ...
- 挖掘两个Integer对象的swap的内幕
public class SwapTest { public static void main(String[] args) throws Exception { Integer a = 1, b=2 ...
- SpringBoot扩展SpringMVC自动配置
SpringBoot中自动配置了 ViewResolver(视图解析器) ContentNegotiatingViewResolver(组合所有的视图解析器) 自动配置了静态资源文件夹.静态首页.fa ...
- C# ASP.NET MVC 配置允许跨域访问
在web.config文件中的 system.webServer 节点下 增加如下配置 <httpProtocol> <customHeaders> <add name= ...
- python 内置函数总结(大部分)
python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...
- oracle 11g 空表导出
背景 oracle9用了一段时间,10用了一段时间,11现在算是主流了.11g也是坑人,空表竟然不导出,解决方法到时很多.这里只是记录下,知道有这个事情. 9的特点是还要用客户端管理工具链接服务器 1 ...
- zabbix3.0监控centos当主机cpu使用率超过90%的时候报警
在windows系统中监控cpu利用率非常容易,自带模板就有这样的功能,但是在linux里面没有默认的模板 只有cpu的负载,默认当cpu的负载在一定时间内5以上报警 cpu utilization中 ...
- sipML5聊天功能实现
一.环境说明:在阅读sipML5的API文档时,发现它具有聊天的功能,于是在sipML5的源码中进行设定,实现了注册之后可以英文聊天(中文聊天需要在FreeSWITCh中进行设定). 二.具体配置: ...