且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将数字转换为一个价格范围

更新时间:2023-02-10 17:48:49

如果psented这个价格结构$ P $我会认为它是在客户的***利益通过购买最适合自己需要的软件包以最小的代价。下面的算法使用动态规划来计算的最小可能的价格准确地购买一定数量的许可证(可以节省的钱购买更多的比你需要的,虽然我还没有实现的):

If presented with this price structure I would think that it is in the customer's best interest to minimize the cost by buying the package that best suits their need. The following algorithm uses dynamic programming to calculate the minimal possible price to exactly buy a certain number of licenses (you can save money by buying more than you need, although I haven't implemented that):

int getPrice(int n)
{
    if (n >= 1 && n <= 10) return 50 * n;
    if (n >= 11 && n <= 20) return 40 * n;
    if (n >= 21 && n <= 30) return 30 * n;
    if (n >= 31 && n <= 50) return 20 * n;
    throw new Exception("Impossible");
}

int minimizePrice(int n)
{
    int[] minimumPrice = new int[n + 1];
    for (int i = 1; i <= n; ++i)
    {
        minimumPrice[i] = int.MaxValue;
        for (int j = Math.Max(0, i - 50); j < i; ++j)
        {
            minimumPrice[i] = Math.Min(minimumPrice[i],
                minimumPrice[j] + getPrice(i - j));
        }
    }
    return minimumPrice[n];
}

有关70执照的最低价格为$ 1400,可以通过购买35许可证2个街区获得。你的建议贪婪算法。这将混淆你的客户。一个聪明的客户将会把两个数量级,而不是一个大订单,节省$ 400元。

For 70 licenses the minimal price is $1400 which can be obtained by buying 2 blocks of 35 licenses. You are suggesting a greedy algorithm. This will confuse your customers. A clever customer will place two orders instead of one large order and save $400.

我建议改变你的价格,以便有没有上限的许可证的数量,你可以在每个$ 20个买了。

I'd suggest changing your prices so that there is no upper limit to the number of licenses you can buy at $20 each.