大体题意:

给你n 种数量无限的灯,告诉你每个灯的电压,电源费用,需要的数量和每个灯泡的价格!你可以把一些灯泡换成更高电压的灯泡,求最少花费?

思路:

题目中说到  通过的电流是一样的,因此电压越高,功率越大,如果换某个灯泡时,必须全部换掉,因为换了其中一个 价格便宜了,肯定全部换掉最划算!

因此转移就很好想了:

先给电压排序!然后枚举换哪一个灯泡,在枚举这个灯泡前面的最优解 + 换灯泡!

详细见代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1000 + 10;
const int inf = 0x3f3f3f3f;
struct Node{
    int V, K, C, L;
    bool operator < (const Node& rhs) const {
        return V < rhs.V;
    }
    void read(){
        scanf("%d %d %d %d",&V, &K, &C, &L);
    }
}p[maxn];
int dp[maxn];
int sum[maxn];
int main(){
    int n;
    while(scanf("%d",&n) == 1 && n){
        memset(dp,inf,sizeof dp);
        dp[0] = 0;
        for (int i = 1; i <= n; ++i){
            p[i].read();
        }
        sort(p+1,p+1+n);
        for (int i = 1; i <= n; ++i){
            sum[i] = sum[i-1] + p[i].L;
        }
        for (int i = 1; i <= n; ++i){
            for (int j = 0; j < i; ++j){
                dp[i] = min(dp[i],dp[j] + (sum[i]-sum[j]) * p[i].C + p[i].K);
            }
        }
        printf("%d\n",dp[n]);
    }
    return 0;
}