标签:
题目很简单,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 }
标签:
原文地址:http://www.cnblogs.com/xiaoshanshan/p/4295190.html