ural 1342. Enterprise
1342. Enterprise
Time limit: 5.0 second
Memory limit: 64 MB
Memory limit: 64 MB
To bind a broom it’s a hard work. As there is a very big demand for this high-tech product an brooms binding enterprise is to have a big amount of production workshops. You are to help such an enterprise to allocate the work among the workshops. Each workshop can bind from 0 to K brooms a day. Economists of the enterprise found out that each bound broom has a different prime cost: in most cases the more brooms were bound a day the less prime cost has the last broom bound that day. However, there may be more complicated situations. As a first approximation you may assume every dependence linear. So decided the economists when they determined a dependence of the next in turn broom’s prime cost on the industrial output of the workshop. You are to find out the optimal work load of the workshops.
Input
The first line contains two integers N and M (1 ≤ N, M ≤ 1000) — an amount of workshops and the required industrial output of brooms, respectively.
Then workshops description follows. The (i+1)-st line describes the i-th workshops with three numbers Ki, Pi, and Qi (1 ≤ Ki ≤ 100; 0 ≤ Pi, Qi ≤ 1000) — they are the maximal number of brooms that can be bound at the i-th workshop a day, the prime cost of the first broom and the prime cost of Ki-th broom at the i-th workshop. As it was mentioned above the cost of j-th broom’s production is the linear with respect to j function.
Output
If the enterprise can’t produce the required number of brooms your program is to output the maximal number of brooms V that can be bound at the enterprise.
Besides, you are to output the total costs on production of M (or V if the enterprise can’t bind M) brooms with optimal allocation of industrial outputs within two digits after a decimal point.
The output format is to be as in sample outputs below.
Samples
input | output |
---|---|
2 10 6 20 15 100 100 100 |
Minimum possible cost: 505.00 |
2 10 5 30 14 1 20 20 |
Maximum possible amount: 6 Minimum possible cost: 130.00 |
Problem Author: Magaz Asanov and Pavel Egorov
Problem Source: USU Championship 2004
Problem Source: USU Championship 2004
Tags: dynamic programming
Difficulty: 861
题意:有n组东西 每组有若干个。价格成一个线性函数,给出上限,初始价格,终止价格。要求买够m个的最少价钱,不够m个输出买最多的最少价钱
分析:
分析:
就是比较裸的dp
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define For(i, s, t) for(int i = (s); i <= (t); i++) 21 #define Ford(i, s, t) for(int i = (s); i >= (t); i--) 22 #define Rep(i, t) for(int i = (0); i < (t); i++) 23 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--) 24 #define rep(i, x, t) for(int i = (x); i < (t); i++) 25 #define MIT (2147483647) 26 #define INF (1000000001) 27 #define MLL (1000000000000000001LL) 28 #define sz(x) ((int) (x).size()) 29 #define clr(x, y) memset(x, y, sizeof(x)) 30 #define puf push_front 31 #define pub push_back 32 #define pof pop_front 33 #define pob pop_back 34 #define ft first 35 #define sd second 36 #define mk make_pair 37 inline void SetIO(string Name) 38 { 39 string Input = Name+".in", 40 Output = Name+".out"; 41 freopen(Input.c_str(), "r", stdin), 42 freopen(Output.c_str(), "w", stdout); 43 } 44 45 46 inline int Getint() 47 { 48 int Ret = 0; 49 char Ch = ' '; 50 bool Flag = 0; 51 while(!(Ch >= '0' && Ch <= '9')) 52 { 53 if(Ch == '-') Flag ^= 1; 54 Ch = getchar(); 55 } 56 while(Ch >= '0' && Ch <= '9') 57 { 58 Ret = Ret * 10 + Ch - '0'; 59 Ch = getchar(); 60 } 61 return Flag ? -Ret : Ret; 62 } 63 64 const int N = 1010; 65 int n, m; 66 DB Arr[N][3], Dp[N][N]; 67 68 inline void Input() 69 { 70 scanf("%d%d", &n, &m); 71 For(i, 1, n) 72 Rep(j, 3) scanf("%lf", &Arr[i][j]); 73 } 74 75 inline void Solve() 76 { 77 Dp[0][0] = 0; 78 For(i, 1, m) Dp[0][i] = 1.0 * INF; 79 DB Delta, x, Cnt; 80 int Len = 0; 81 For(i, 1, n) 82 { 83 For(j, 0, m) Dp[i][j] = Dp[i - 1][j]; 84 if(Arr[i][0] > 1) Delta = (Arr[i][2] - Arr[i][1]) / (Arr[i][0] - 1); 85 86 x = Cnt = Arr[i][1]; 87 For(j, 1, Arr[i][0]) 88 { 89 For(k, 0, Len) 90 if(Dp[i][k + j] > Dp[i - 1][k] + x) 91 Dp[i][k + j] = Dp[i - 1][k] + x; 92 Cnt += Delta; 93 x += Cnt; 94 } 95 96 Len += Arr[i][0]; 97 if(Len > m) Len = m; 98 } 99 100 if(Len < m) 101 printf("Maximum possible amount: %d\n", Len); 102 printf("Minimum possible cost: %.2f\n", Dp[n][Len]); 103 } 104 105 int main() 106 { 107 #ifndef ONLINE_JUDGE 108 SetIO("E"); 109 #endif 110 Input(); 111 Solve(); 112 return 0; 113 }