动态规划uva11400

题目链接

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int maxn = 1000+5;
 5 
 6 struct Lamp{
 7     int v,k,c,l;
 8     bool operator<(const Lamp& rhs)const{
 9         return v<rhs.v;
10     }
11 }lamp[maxn];
12 
13 
14 int n,s[maxn],d[maxn];
15 
16 int main(){
17     while(cin >> n && n){
18         for(int i=1; i<=n; i++)
19             cin >> lamp[i].v >> lamp[i].k >> lamp[i].c >> lamp[i].l;
20         sort(lamp+1,lamp+1+n);
21         s[0] = 0;
22         for(int i=1; i<=n; i++) s[i] = s[i-1]+lamp[i].l;
23         d[0] = 0;
24         for(int i=1; i<=n; i++){
25             d[i] = s[i]*lamp[i].c +lamp[i].k;
26             for(int j=1; j<=i; j++)
27                 d[i] = min(d[i],d[j]+(s[i]-s[j])*lamp[i].c+lamp[i].k);
28         }
29         cout << d[n] << "
";
30     }
31 
32 }
原文地址:https://www.cnblogs.com/yxg123123/p/6827750.html