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 }
  • 相关阅读:
    perl的eval语句
    PythonWin运行出错解决办法
    python多重继承
    perl调用shell
    python正则表达式匹配中文
    perl学习2处理用户输入
    awk介绍
    perl学习3qw及数组的应用
    perl的多线程
    perl学习5子程序中自动识别参数
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4056583.html
Copyright © 2011-2022 走看看