码迷,mamicode.com
首页 > 其他好文 > 详细

uva 11400 (动态规划起步第四天 线性DP)

时间:2015-02-17 14:05:35      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

题目很简单,LIS变形

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <set>
 5 #include <algorithm>
 6 
 7 #define REP(i,N) for (int i = 0;i < (N);i++)
 8 #define REP_1(i,N) for (int i = 1;i < (N);i++)
 9 #define DWN(i,N) for (int i = (N);i >= 0;i--)
10 #define INF 0x3f3f3f3f
11 #define MAXN 1010
12 
13 using namespace std;
14 
15 class Node{
16     public:
17         int v,k,c,l;
18         Node() {}
19         Node (int v,int k,int c,int l):v(v),k(k),c(c),l(l) {}
20         bool operator < (const Node& rhs) const {
21             return v < rhs.v;
22         }
23 };
24 Node node[MAXN];
25 int dp[MAXN];
26 int sum[MAXN];
27 int main () {
28     int N;
29     //freopen("1.txt","r",stdin);
30     while (cin >> N,N) {
31         int v,k,c,l;
32         REP(i,N) {
33             cin >> v >> k >> c >> l;
34             node[i] = Node(v,k,c,l);
35         }
36         memset(dp,0,sizeof(dp));
37         sort(node,node + N);
38         sum[0] = node[0].l;
39         REP_1(i,N) {
40             sum[i] = sum[i - 1] + node[i].l;
41         }
42         REP(i,N) {
43             dp[i] = sum[i] * node[i].c + node[i].k;
44             REP(j,i) {
45                 dp[i] = min(dp[i],dp[j] + (sum[i] - sum[j]) * node[i].c + node[i].k);
46             }
47         }
48         cout << dp[N - 1] << endl;
49     }
50     return 0;
51 }

 

uva 11400 (动态规划起步第四天 线性DP)

标签:

原文地址:http://www.cnblogs.com/xiaoshanshan/p/4295190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!