UVA11400照明系统设计

题目如下:
You are given the task to design a lighting system for a huge conference hall. After doing a lot of
calculation and sketching, you have figured out the requirements for an energy-efficient design that
can properly illuminate the entire hall. According to your design, you need lamps of n different power
ratings. For some strange current regulation method, all the lamps need to be fed with the same
amount of current. So, each category of lamp has a corresponding voltage rating. Now, you know the
number of lamps and cost of every single unit of lamp for each category. But the problem is, you are
to buy equivalent voltage sources for all the lamp categories. You can buy a single voltage source for
each category (Each source is capable of supplying to infinite number of lamps of its voltage rating.)
and complete the design. But the accounts section of your company soon figures out that they might
be able to reduce the total system cost by eliminating some of the voltage sources and replacing the
lamps of that category with higher rating lamps. Certainly you can never replace a lamp by a lower
rating lamp as some portion of the hall might not be illuminated then. You are more concerned about
money-saving than energy-saving. Find the minimum possible cost to design the system.
Input
Each case in the input begins with n (1 ≤ n ≤ 1000), denoting the number of categories. Each of the
following n lines describes a category. A category is described by 4 integers - V (1 ≤ V ≤ 132000), the
voltage rating, K (1 ≤ K ≤ 1000), the cost of a voltage source of this rating, C (1 ≤ C ≤ 10), the cost
of a lamp of this rating and L (1 ≤ L ≤ 100), the number of lamps required in this category. The input
terminates with a test case where n = 0. This case should not be processed.
Output
For each test case, print the minimum possible cost to design the system.
Sample Input
3
100 500 10 20
120 600 8 16
220 400 7 18
0
Sample Output
778

这坑爹的题目我就读了好久才明白是什么意思,就是说如果n种灯泡要全部使用的话呢,每种要Li个才行,然后额定电压低的灯泡呢可以用额定电压高的灯泡替换。
从规则上看,很容易知道每种电压下的灯泡要么不换要么全换,并且只能用电压高的换电压低的,不然的话电源的费用会更多。
所以呢,可以先把灯泡按照电压的大小从小到大排序,设s[i]为前i种灯泡的所需的数量(换不换灯泡都要这么多灯泡)。剩下来就是用什么来表示状态了。既然和灯泡的选用的种类有关系,那么就用d(i)表示有前i灯泡时的最小开销,则状态转移方程为d[i]=min(d[i],d[j]+(s[i]-s[j])*c[i]+k[i]),用j来遍历只用前j种灯泡而剩下的灯泡用第i种的各个情况的费用。
AC代码:

// UVA11400.cpp : 定义控制台应用程序的入口点。
//

#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn = 1005;
struct Lamp
{
    int V;
    int K;
    int C;
    int L;

};
Lamp arr[maxn];
int s[maxn];
int dp[maxn];
bool comp(const Lamp &a, const Lamp &b)
{
    return a.V < b.V;
}
int main()
{
    int n = 0;
    while (cin >> n&&n != 0)
    {
        memset(s, 0, sizeof(s));
        memset(arr, 0, sizeof(arr));
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i < n; i++)
            cin >> arr[i].V >> arr[i].K >> arr[i].C >> arr[i].L;
        sort(arr, arr + n, comp);//因为低电压可以被高电压的取代,反之不行,所以先对电压值进行个排序
        for (int i = 0; i < n; i++){//显然电源的花费能省就省,所以每个电压下的灯泡要么都换掉,要么都不换
            i>0 ? s[i] = arr[i].L + s[i - 1] : s[i] = arr[i].L;//计算出每个电压额度下需要的灯泡数
            dp[i] = arr[i].K + arr[i].C*s[i];//计算出全部使用i种灯泡的花费
        }

        for (int i = 1; i < n; i++)
        for (int j = 0; j < i; j++)
            if (dp[i]>dp[j] + (s[i] - s[j])*arr[i].C + arr[i].K)
                dp[i] = dp[j] + (s[i] - s[j])*arr[i].C + arr[i].K;

            cout << dp[n - 1] << endl;
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值