UVa1628 UVaLive5847 Pizza Delivery
填坑系列(p.302)
既然不知道后面还要卖多少个就加一维状态嘛。。
lrj写的O(n)转移?其实转移可以O(1)
貌似按x排序有奇效?
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> using namespace std; void setIO(const string& s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} const int N = + , INF = 0x3f3f3f3f; int p[N], v[N], n, cas;
int f[N][N][N][];
int vis[N][N][N][]; int dfs(int s, int e, int cnt, int pos) {
if(!cnt) return ;
int &ans = f[s][e][cnt][pos];
if(vis[s][e][cnt][pos] == cas) return ans;
vis[s][e][cnt][pos] = cas; ans = -INF;
int a[] = {s, e}; /*for(int i = 0; i < s; i++) {
ans = max(ans, v[i] - cnt * abs(p[i] - p[a[pos]]) + dfs(i, e, cnt - 1, 0));
}
for(int i = e + 1; i < n; i++) {
ans = max(ans, v[i] - cnt * abs(p[i] - p[a[pos]]) + dfs(s, i, cnt - 1, 1));
}*/ if(s - >= ) {
int dlt = cnt * abs(p[s - ] - p[a[pos]]);
ans = max(ans, v[s - ] - dlt + dfs(s - , e, cnt - , ));
ans = max(ans, -dlt + dfs(s - , e, cnt, ));
}
if(e + < n) {
int dlt = cnt * abs(p[e + ] - p[a[pos]]);
ans = max(ans, v[e + ] - dlt + dfs(s, e + , cnt - , ));
ans = max(ans, -dlt + dfs(s, e + , cnt, )) ;
} return ans;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int T; scanf("%d", &T);
for(cas = ; cas <= T; cas++) {
scanf("%d", &n);
for(int i = ; i < n; i++) scanf("%d", p + i);
for(int i = ; i < n; i++) scanf("%d", v + i); int ans = ;
for(int k = ; k <= n; k++) {
for(int i = ; i < n; i++) {
ans = max(ans, v[i] - k * abs(p[i]) + dfs(i, i, k - , ));
}
}
printf("%d\n", ans);
} return ;
}
UVa1628 UVaLive5847 Pizza Delivery的更多相关文章
- 【暑假】[深入动态规划]UVa 1628 Pizza Delivery
UVa 1628 Pizza Delivery 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51189 思路: ...
- Pizza Delivery
Pizza Delivery 时间限制: 2 Sec 内存限制: 128 MB 题目描述 Alyssa is a college student, living in New Tsukuba Cit ...
- uva1628 Pizza Delivery
fixing great wall 的变形dp(i,j,k,p)不考虑i-j的客人,还要送k个人,目前位置在p起点i和总数量k都要枚举dp(i,j,k,p)=max(dp(m,j,k-1,p)+val ...
- Aizu - 1383 Pizza Delivery (最短路图+DAG上的割边)
题意:给出一张有向图,每条边有长度,对于每条边,你要回答将该边的方向取反后,从起点到终点的最短距离是增加or减小or不变. 首先求出起点到所有点的最短距离和所有点到终点的最短距离(两次DIjkstra ...
- (好题)2017-2018 ACM-ICPC, Asia Tsukuba Regional Contest F Pizza Delivery
题意:给n个点m条边的有向图.每次使一条边反向,问你1到2的最短路变短,变长,还是不变. 解法:遇到这种题容易想到正向求一遍最短路d1,反向再求一遍最短路d2.纪录原图上的最短路为ans,然后分开考虑 ...
- [GodLove]Wine93 Tarining Round #1
比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44664#overview 题目来源: 2011 Asia Regional ...
- CodeForces 151B Phone Numbers
Phone Numbers Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
- Asia-Tsukuba 2017
A. Secret of Chocolate Poles DP,$f[i][j]$表示高度为$i$,顶层颜色为$j$的方案数. 时间复杂度$O(l)$. #include<cstdio> ...
- 2017-2018 ACM-ICPC, Asia Tsukuba Regional Contest
2017-2018 ACM-ICPC, Asia Tsukuba Regional Contest A Secret of Chocolate Poles 思路:暴力枚举黑巧克力的个数和厚黑巧克力的个 ...
随机推荐
- 忘记Mysql的root密码怎么办?
解决方法: 1.打开cmd,用net start命令查看是否开启了mysql服务,如果开启,用net stop mysql 命令关闭mysql 2.进入mysql的安装目录下的bin目录,例如:E:\ ...
- 浅谈ListBox控件,将对象封装在listBox中,在ListBox中显示对象中某个属性,在ListBox中移除和移动信息
大家好,俗称万事开头难,不经历风雨,怎能见彩虹.在此小编给大家带来一个自己练习的小实例,希望与大家一起分享与交流.下面进入应用场景,从SQL2008数据库取出数据,给ListBox赋值在界面并显示出来 ...
- Web动效研究与实践
随着CSS3和HTML5的发展,越来越多狂拽炫酷叼炸天的动效在网页设计上遍地开花,根据最新的浏览器市场份额报告,IE6的份额已经降到了5.21%,这简直是一个喜大普奔的消息,做动效可以完全不care低 ...
- mysql datestamp坑
每次更改行数据,该行第一个datestamp如不赋值,会自动更新为当前时间.赋值还要注意用下new Date(time).updated_at要写在created_at前面...
- 学学Whatsapp,如何让自己挣160亿美金,然后退休?开发个J2ME应用。
facebook用160亿美元收购了Whatsapp,要知道这是facebook市值1600亿美元的十分之一,而Whatsapp是一个只有50名员工的小公司,这个价格让硅谷各种科技公司大佬跌破镜框.其 ...
- 机务UI设计小节
1.CSS样式 .header { background-color:#7A8692; color:White; height:30px; font-size:16px; width:100%; li ...
- JavaScriptCore-b
JavaScriptCore提供了JavaScript和Objective-C桥接的Obj-C API.JavaScriptCore提供了让我们脱离UIWebView执行JavaScript脚本的能力 ...
- 自定义UICollectionViewController之后 如何设置UICollectionView的布局方式--备用
我们很多时候使用UICollectionView 可能都是直接创建 UICollectionView 通过初始化的时候 传入一个布局对象的方式来使用UICollectionView 比如我们之前 ...
- SpringMVC源码阅读(二)
今天分析下ViewResolver和View的实现 下面是ModelAndView的实现 package org.springframework.web.servlet; import java.u ...
- Linux下的echo服务器
epoll模式下的echo服务器,忘记从哪个网页上粘贴过来的了,学习一下 /* * main.cc * * Created on: 2009-11-30 * Author: liheyuan * De ...