1628 Pizza Delivery

There is a pizza house located on a straight road, and there are many houses along the road which are
customers to the pizza house. To attract more orders from his customers, the owner of the pizza house
advertised that he will deduct a penalty for late delivery from the price of the delivered pizzas. The
penalty is to be charged when some designated time period has passed after the order has been made,
and the amount of penalty to be charged is 1 Korean Won per unit time thereafter. Today all houses on
the road ordered pizza at the same time and the delivery of all the ordered pizzas has just started when
the late delivery penalty is going to be charged. On a busy day like today, he may not deliver pizza to
some customers if the late delivery penalty to be deducted for a customer is more than the earning to
be made by selling pizza to the customer. Write a program to help him decide to which customers he
has to deliver pizzas and which customers he may skip in order to make the greatest pro t. Note that
the pro t made by delivering a pizza to a customer is the amount of earning from the service deducting
the penalty for late delivery. You may assume that his moving velocity is one unit distance per unit
time and it takes no time to hand over the pizza to the customer.
For example, the following gure shows the relative positions of ve customers fc1; c2; : : : ; c5g to
the pizza house and the earning to be made by selling pizzas to each customer.
If the delivering sequence of customers is < c4; c3; c2; c5; c1 >, then the amount of penalty for late
delivery to each customer is 2 for c4, 5 for c3, 7 for c2, 15 for c5 and 26 for c1. In this case the pro t from
each customer is 3 for c4, -3 for c3, 3 for c2, 5 for c5 and 1 for c1. Since the pro t from customer c3 is -3,
it is better not to deliver pizza to c3. Therefore the total pro t by delivering pizzas to the customers in
this order is 12. The best pro t the owner can make, in this case, is 32, where the delivering sequence
is < c3; c2; c1; c5 >.
Given the relative positions of customers to pizza house, and earnings to be made by delivering
pizzas to each customer, write a program to compute the maximum pro ts by delivering pizzas ordered
from the customers.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test
cases T is given in the rst line of the input. Each test case consists of three lines. The rst line of
each test case contains an integer, n (1 n 100), which is the number of customers to pizza house.
The second line of each test case contains n integers p1, p2, … , pn (p1 < p2 < : : : < pn and pi = 0, ̸
i = 1; : : : ; n), where pi
is the relative position of the i-th customer ci to the pizza house on the straight
road. The third line of each test case contains n integers e1, e2, … , en (ei > 0, i = 1; : : : ; n), where eiUniversidad de Valladolid OJ: 1628 { Pizza Delivery 2/2
is the earning to be made by delivering pizzas to the customer ci
. All integers in the second and third
lines are between -100,000 and 100,000 both inclusive.
Output
Your program is to write to standard output. Print exactly one line for each test case. The line should
contain the maximum pro t by delivering pizzas ordered from the customers.
The following shows sample input and output for three test cases.
Sample Input
3
5
-6 -3 -1 2 5
27 10 2 5 20
6
1 2 4 7 11 14
3 6 2 5 18 10
11
-14 -13 -12 -11 -10 1 2 3 4 5 100
200 200 200 200 200 200 200 200 200 200 200
Sample Output
32
13
1937

有一个披萨的房子位于直路,还有很多房子的路
客户的披萨。吸引更多的订单从他的客户,披萨的主人的房子
广告,他将从价格中扣除惩罚延误发货的比萨饼交付。的
惩罚时要收取一些订单后指定时间已经过了,
和被处罚的数量是1韩元单位时间。今天,所有的房屋
路同时订购比萨饼和交付的所有订购比萨饼刚刚开始的时候
迟交罚款将被起诉。在今天这样一个忙碌的一天,他可能不会提供披萨
一些客户如果迟交罚款扣除客户超过收入
由卖披萨给客户。编写一个程序来帮助他决定哪些客户
必须交付比萨饼和哪些客户可以跳过为了使最大的保护。请注意,
港由交付比萨饼客户从服务的收入扣除
惩罚延误发货。你可能认为他的移动速度是一个单位距离单位
需要时间和没有时间去比萨交给客户。
例如,下面的gure显示已经客户的相对位置fc1;c2,:::;c5g
披萨的房子和收入由卖披萨给每个客户。
如果客户的交付顺序是< c4、c3、c2、c5、c1 >,然后惩罚延误的数量
交付为c4每个客户是2、5 c3,c5 7 c2、15和26 c1。在这种情况下,普罗特
每个客户是3 c4,3为c3,3为c2 5 c5 1 c1。自普罗特从客户c3是3
最好是不提供比萨c3。因此,总普罗特向客户交付比萨饼
此订单是12。最好的普罗特所有者可以在这种情况下,是32,交付序列
是< c3,c2,c1,c5 >。
考虑到客户的相对位置披萨的房子,和收益是由交付
披萨给每个客户,写一个程序来计算最大防送批萨饼命令
从客户。
输入
程序从标准输入读取。输入包括T测试用例。测试的数量
案例中给出了T的第一行输入。每个测试用例包含三行。的第一行
每个测试用例包含一个整数,n(100 n),客户数量的披萨。
每个测试用例的第二行包含n个整数p1,p2,。pn(p1 < p2 <:::< pn和π= 0,̸
我= 1,:::;n),pi
的相对位置的第i个客户ci直上的披萨的房子吗
路。每个测试用例的第三行包含n个整数e1,e2,。,(ei > 0,我= 1,:::;n),eiUniversidad德巴利亚多利德橙汁:1628 {披萨外卖2/2
的收入是由客户ci送批萨饼
。第二个和第三个整数
行是在-100000年和100000年之间包容。
输出
你的程序是编写到标准输出。为每个测试用例完全打印一行。行应该
包含最大普罗特送批萨饼从客户订购。
下面显示了三个测试用例样本的输入和输出。
样例输入
3
5
6 3 1 2 5
27日20 10 2 5
6
1 2 4 7 11 14
3 6 2 5 18 10
11
-14 -13 -12 -11 -13 100 1 2 3 4 5
200 200 200 200 200 200 200 200 200 200 200
样例输出
32
13
1937
我有话说:
我简单的说一下题目大意。就是一个坐标轴上有n个客户。原点O是披萨店。一个送货员从店里出发送货。而每个客户支付的费用是ei-ti。ei是最初付款,ti是送到货等待的时间。求送货员最多获得的钱。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100 + 5;

int kase, n;
int p[maxn], v[maxn];
int d[maxn][maxn][maxn][2];
int vis[maxn][maxn][maxn][2];

//考虑s到e的所有的人都已经收到了货或者放弃送货。
// pos = 0意味在s, pos = 1意味在e,cnt是还需要送货的人数
int dp(int s, int e, int cnt, int pos) {
  if(cnt == 0) return 0;

  int &ans = d[s][e][cnt][pos];//当前状态最所能获得的钱
  if(vis[s][e][cnt][pos] == kase) return ans;//标记
  vis[s][e][cnt][pos] = kase;

  ans = 0;  
  if(!pos) {//在s
    for(int i = 0; i < s; i++)
      ans = max(ans, v[i] - cnt * abs(p[i] - p[s]) + dp(i, e, cnt - 1, 0));//意味着送到i需要的时间,再乘上所有剩下客户cnt就是总罚款数
    for(int i = e + 1; i < n; i++)
      ans = max(ans, v[i] - cnt * abs(p[i] - p[s]) + dp(s, i, cnt - 1, 1));
  }
  else {
    for(int i = 0; i < s; i++)
      ans = max(ans, v[i] - cnt * abs(p[i] - p[e]) + dp(i, e, cnt - 1, 0));
    for(int i = e + 1; i < n; i++)
      ans = max(ans, v[i] - cnt * abs(p[i] - p[e]) + dp(s, i, cnt - 1, 1));
  }
  return ans;
}

int main() {
  int T;
  scanf("%d",&T);
  memset(vis, 0, sizeof(vis));
  for(kase = 1; kase <= T; kase++) {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &p[i]);
    for(int i = 0; i < n; i++) scanf("%d", &v[i]);

    int ans = 0;
    for(int k = 1; k <= n; k++)//选择要总共送货的客户的数量
      for(int i = 0; i < n; i++)//选择从哪个客户开始送货
        ans = max(ans, v[i] - k * abs(p[i]) + dp(i, i, k - 1, 0));
    printf("%d\n",ans);
  }
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值