zoukankan      html  css  js  c++  java
  • 【HDOJ】1158 Employment Planning

    简单DP。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cstdlib>
     4 #include <climits>
     5 #define MAXN 105
     6 
     7 int dp[15][MAXN];
     8 int a[15];
     9 
    10 int getMin(int a, int b) {
    11     return a<b?a:b;
    12 }
    13 
    14 int main() {
    15     int n, max, min;
    16     int i, j, k, r, tmp, ans;
    17     int hire, salary, fire;
    18 #ifndef ONLINE_JUDGE
    19     freopen("data.in", "r", stdin);
    20 #endif
    21     while (scanf("%d",&n)!=EOF && n) {
    22         scanf("%d %d %d", &hire, &salary, &fire);
    23         max = INT_MIN;
    24         min = INT_MAX;
    25         for (i=1; i<=n; ++i) {
    26             scanf("%d", &a[i]);
    27             if (a[i] > max)
    28                 max = a[i];
    29             if (a[i] < min)
    30                 min = a[i];
    31         }
    32         for (r=1; r<=n; ++r) {
    33             for (i=a[r]; i<=max; ++i) {
    34                 if (r == 1) {
    35                     dp[r][i] = i*(hire+salary);
    36                     continue;
    37                 }
    38                 ans = INT_MAX;
    39                 for (j=a[r-1]; j<=max; ++j) {
    40                     tmp = dp[r-1][j] + i*salary;
    41                     if (j >= i) {
    42                         ans = getMin(ans, tmp+(j-i)*fire);
    43                     } else {
    44                         ans = getMin(ans, tmp+(i-j)*hire);
    45                     }
    46                 }
    47                 dp[r][i] = ans;
    48             }
    49         }
    50         ans = INT_MAX;
    51         for (i=a[n]; i<=max; ++i)
    52             if (dp[n][i] < ans)
    53                 ans = dp[n][i];
    54         printf("%d
    ", ans);
    55     }
    56 
    57     return 0;
    58 }
  • 相关阅读:
    C语言基础-第一章
    C语言基础-第三章
    C语言基础-第五章
    怎样在WIN7系统下安装IIS
    Asp.Net中使用水晶报表(下)
    Asp.Net中使用水晶报表(中)
    Asp.Net 中使用 水晶报表(上)
    A1112. Stucked Keyboard
    A1111. Online Map
    A1110. Complete Binary Tree
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4056583.html
Copyright © 2011-2022 走看看