【dp】ZOJ 3469

最近的题解都是写在本子上的……

不对……最近也没写多少题解……

还是恢复写题解的习惯吧……做了的题再分析一下印象深刻些……这就是本弱写题解的目的了……

废话完毕!

Food Delivery

Time Limit: 2 Seconds      Memory Limit: 65536 KB

When we are focusing on solving problems, we usually prefer to stay in front of computers rather than go out for lunch. At this time, we may call for food delivery.

Suppose there are N people living in a straight street that is just lies on an X-coordinate axis. The ith person's coordinate is Xi meters. And in the street there is a take-out restaurant which has coordinates X meters. One day at lunchtime, each person takes an order from the restaurant at the same time. As a worker in the restaurant, you need to start from the restaurant, send food to the N people, and then come back to the restaurant. Your speed is V-1 meters per minute.

You know that the N people have different personal characters; therefore they have different feeling on the time their food arrives. Their feelings are measured by Displeasure Index. At the beginning, the Displeasure Index for each person is 0. When waiting for the food, the ith person will gain Bi Displeasure Index per minute.

If one's Displeasure Index goes too high, he will not buy your food any more. So you need to keep the sum of all people's Displeasure Index as low as possible in order to maximize your income. Your task is to find the minimal sum of Displeasure Index.

Input

The input contains multiple test cases, separated with a blank line. Each case is started with three integers N ( 1 <= N <= 1000 ), V ( V > 0), X ( X >= 0 ), then N lines followed. Each line contains two integers Xi ( Xi >= 0 ), Bi ( Bi >= 0), which are described above.

You can safely assume that all numbers in the input and output will be less than 231 - 1.

Please process to the end-of-file.

Output

For each test case please output a single number, which is the minimal sum of Displeasure Index. One test case per line.

Sample Input

5 1 0
1 1
2 2
3 3
4 4
5 5

Sample Output

55

题目大意:有一个人他外卖员要去送外卖,他的店在X位置,他的速度为V,然后现在有N个人要外卖,坐标分别为Xi, 这N个人每等一分钟不满意度增加Bi,他送完所有人要让总的不满意度最少求最少的不满意度是多少……(语死早,总是描述不清楚题目在说什么)
看起来就像个区间dp,但是……于是就去看题解了,果然功力还很弱……
首先我们可以知道,他肯定是从店铺所在位置向两边送(至于每次每边送多远就是需要dp算的了)
f[i][j][0]表示送完[i,j]这个区间且送货员停在i位置,的最小不满值
f[i][j][1]表示送完[i,j]这个区间且送货员停在j位置,的最小不满值

f[i][j][0] = min(f[i][j][0], f[i + 1][j][0] + (a[i + 1].x - a[i].x) * (add + a[i].v)) * v;
f[i][j][1] = min(f[i][j][1], f[i][j - 1][1] + (a[j].x - a[j - 1].x) * (add + a[j].v)) * v ;
f[i][j][0] = min(f[i][j][0], f[i + 1][j][1] + (a[j].x - a[i].x) * (add + a[i].v)) * v;
f[i][j][1] = min(f[i][j][1], f[i][j - 1][0] + (a[j].x - a[i].x) * (add + a[j].v)) * v;

其中add 是所有不在[i,j]区间里的每个客户的单位时间不满意度增长量之和(可用前缀和O(1)求出)
这里要注意由于 “ Your speed is V-1 meters per minute.” 
也就是是说V其实是速度的倒数……
因为add + a[i].v 等为每个客户的单位时间不满意度增长量之和
而(a[i + 1].x - a[i].x)等为等待的路程
所以 等待的时间是  (a[i + 1].x - a[i].x) * V
但是,如果把V直接在转移的时候乘进去的话中间结果会爆int,得用long long
所以可以一直不乘 V,到输出的时候再乘上!
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
int n, v, x;
struct ty
{
    int x, v;
}a[1010];
int f[1010][1010][3];
int sum[1010];
bool comp(ty a, ty b)
{
    return a.x < b.x;
}
int calc(int i, int j, int k, int l)
{
    return sum[j] - sum[i - 1] + sum[l] - sum[k - 1];
}
int main()
{
    while (scanf("%d%d%d", &n, &v, &x) != EOF)
    {
        for (int i = 1; i <= n; i++)
        {
            scanf("%d%d", &a[i].x, &a[i].v);
        }
        a[n + 1].x = x, a[n + 1].v = 0;
        n++;
        sort(a + 1, a+ n + 1, comp);
        memset(sum, 0, sizeof(sum));
        for(int i = 1; i <= n; i++)
            sum[i] = sum[i - 1] + a[i].v;

        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            f[i][j][0] = f[i][j][1] = 0x3f3f3f3f;
        }
        int pos = 0;
        for (int i = 1; i <= n; i++)
        {
            if (a[i].x == x && a[i].v == 0) {pos = i; break;}
        }

        f[pos][pos][0] = f[pos][pos][1] = 0;
        for(int i = pos; i >= 1; i--)
        {
            for (int j = pos; j <= n; j++)
            {
                if (i == j) continue;
                int add = calc(1, i - 1, j + 1, n);
                f[i][j][0] = min(f[i][j][0], f[i+1][j][0]+(a[i+1].x-a[i].x)*(add+a[i].v));
                f[i][j][1] = min(f[i][j][1], f[i][j-1][1]+(a[j].x-a[j-1].x)*(add+a[j].v));
                f[i][j][0] = min(f[i][j][0], f[i+1][j][1]+(a[j].x-a[i].x)*(add+a[i].v));
                f[i][j][1] = min(f[i][j][1], f[i][j-1][0]+(a[j].x-a[i].x)*(add+a[j].v));
            }
        }

        printf("%d\n", min(f[1][n][0], f[1][n][1]) * v);
    }
    return 0;
}



### 关于ZOJ 2193题目描述与解决方案 对于ZOJ 2193的具体题目描述未能直接从当前提供的参考资料中找到对应的信息。然而,在处理此类竞赛编程问题时,通常遵循一定的模式来解析和解决。 #### 动态规划的应用场景 当面对涉及序列优化的问题时,动态规划是一种常见的有效方法[^1]。虽然此原则适用于许多算法挑战,但对于特定编号为2193的ZOJ问题而言,具体的实现细节会有所不同。 #### 数据结构的选择 针对某些类型的查询操作频繁的数据集,采用合适的数据结构可以显著提高效率。例如,在处理区间更新或查询的情况下,线段树是一个强有力的选择[^4]。不过这取决于具体问题的需求,并不一定适合ZOJ 2193。 #### 数学模型构建的重要性 一些离散数学概念如组合计数、概率论以及特殊情况下像约瑟夫环这样的经典问题能够帮助建立有效的数学模型来进行求解[^2]。尽管这些技巧广泛应用于各类编程比赛中,它们是否能用于解答ZOJ 2193还需进一步确认该题目的具体内容。 为了获得关于ZOJ 2193更精确的帮助,建议访问原网站获取官方文档中的确切表述或者查阅其他参赛者分享的经验贴以了解可能存在的高效解法路径。 ```python # 此处提供一个通用框架作为参考而非特指ZOJ 2193的答案 def solve_problem(input_data): # 假设输入数据已经预处理完成并存储在input_data变量里 result = [] # 存储最终的结果列表 n = len(input_data) dp = [0]*n # 初始化dp数组用来记录状态转移过程中的最优子结构信息 for i in range(n): # 更新dp[i], 这里的逻辑应该基于实际问题定义而定 pass return result ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值