1628 Pizza Delivery
来源:互联网 发布:2016淘宝下半年活动 编辑:程序博客网 时间:2024/05/17 04:11
按照紫书的思路,重点在于可以忽略有哪些具体的位置没有送到,而仅仅关注于已经送到的地方以及下一步需要送到哪些地方,具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>using namespace std;int T,n;int position[110], value[110];int dp[110][110][2][110];int visit[110][110][2][110];int get(int l,int r,int pos,int amount){if (amount == 0) return 0;if (visit[l][r][pos][amount] == T) return dp[l][r][pos][amount];visit[l][r][pos][amount] = T;int& ans = dp[l][r][pos][amount];ans = 0;for (int i = 0; i < l; i++) ans = max(ans, get(i, r, 0, amount - 1) - amount*abs(position[i] -(pos ? position[r] : position[l])) + value[i]);for (int i = n - 1; i > r; i--) ans = max(ans, get(l, i, 1, amount - 1) - amount*abs(position[i] -(pos ? position[r] : position[l])) + value[i]);return ans;}int main(){cin >> T;memset(visit,0,sizeof(visit));while (T--){cin >> n;for (int i = 0; i < n; i++) cin >> position[i];for (int i = 0; i < n; i++) cin >> value[i];int ans = 0;for (int k = 1; k <= n; k++){for (int i = 0; i < n; i++){ans = max(ans, get(i, i, 0, k - 1) - k*abs(position[i]) + value[i]);}}cout << ans << endl;}}
阅读全文
0 0
- 1628 Pizza Delivery
- 1628 Pizza Delivery
- Uva-1628 Pizza Delivery(机智DP)
- 【暑假】[深入动态规划]UVa 1628 Pizza Delivery
- Hoj 1020 Afshung Pizza Delivery
- GETZ PIZZA – Home Delivery Management
- PIZZA
- codechef December Challenge 2012 Pizza Delivery 完全背包求最小值 这道很重
- Delivery
- Delivery Completed
- Continuous Delivery
- Delivery SQL
- Content Delivery
- Pizza Hut的账单
- 创意程序Pizza Party
- UVA 11704 - Caper pizza
- UVa 565 - Pizza Anyone?
- uva 565 - Pizza Anyone?
- 大疆提前批Android端 终面
- 【HTML5】——表单
- html经典布局(适用于移动端)
- 重新学习c#面向对象程序设计
- 【1】C#基础:数据类型、运算、随机、枚举、结构、数组、列表、文件和文件流、序列化、MD5
- 1628 Pizza Delivery
- vins资料网址
- 前端必须要注意的规范(三)之js规范
- 阴影的生成
- [LeetCode]22. Generate Parentheses
- 大疆提前批Android端 终面后加面
- 获取网络json+图片
- 算法竞赛入门经典(第二版)第一章课后习题
- bootstrap预设置