| Cent Savings |
| Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB |
| Total submit users: 56, Accepted users: 40 |
| Problem 13345 : No special judgement |
| Problem description |
|
To host a regional contest like NWERC a lot of preparation is necessary: organizing rooms and computers, making a good problem set, inviting contestants, designing T-shirts, book- ing hotel rooms and so on. I am responsible for going shopping in the supermarket. |
| Input |
|
The input consists of: |
| Output |
|
Output the minimum amount of money needed to buy all the items, using up to d dividers. |
| Sample Input |
5 1 13 21 55 60 42 5 2 1 1 1 1 1 |
| Sample Output |
190 0 |
题意:一个长度为n的序列a[i],可以序列分成1~d + 1段,每段的和对个位数4舍5入, 求总和的最小值。
思路:dp[i][j] = min(dp[i - 1][j] + a[i], (dp[i - 1][j - 1] + 5) / 10 * 10 + a[i]);
dp[i][j] 表示前i个数分成j + 1段的最小和。
1 #include<algorithm> 2 #include<iostream> 3 #include<limits.h> 4 #include<stdlib.h> 5 #include<string.h> 6 #include<complex> 7 #include<cstring> 8 #include<iomanip> 9 #include<stdio.h> 10 #include<bitset> 11 #include<cctype> 12 #include<math.h> 13 #include<string> 14 #include<time.h> 15 #include<vector> 16 #include<cmath> 17 #include<queue> 18 #include<stack> 19 #include<list> 20 #include<map> 21 #include<set> 22 23 #define LL long long 24 25 using namespace std; 26 const LL mod = 1e9 + 7; 27 const double PI = acos(-1.0); 28 const double E = exp(1.0); 29 const int M = 1e5 + 5; 30 31 int a[2005]; 32 int dp[2005][22]; 33 34 inline int calc(int x) 35 { 36 return (x + 5) / 10 * 10; 37 } 38 39 int main() 40 { 41 int n, d; 42 while( cin >> n >> d ){ 43 memset(dp, 0, sizeof(dp)); 44 for(int i = 1; i <= n; ++i){ 45 cin >> a[i]; 46 dp[i][0] = dp[i - 1][0] + a[i]; 47 } 48 for(int i = 1; i <= n; ++i) 49 for(int j = 1; j <= d; ++j) 50 dp[i][j] = min(dp[i - 1][j] + a[i], calc(dp[i - 1][j - 1]) + a[i]); 51 52 int mn = INT_MAX; 53 for(int i = 0; i <= d; ++i) 54 mn = min(mn, calc(dp[n][i])); 55 cout << mn << endl; 56 } 57 return 0; 58 }
浙公网安备 33010602011771号