zoukankan      html  css  js  c++  java
  • UVA 607 二十二 Scheduling Lectures

    Scheduling Lectures
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Appoint description: 

    Description

    Download as PDF
     

    You are teaching a course and must cover n ( $1 le n le 1000$) topics. The length of each lecture is L ( $1 le L le 500$) minutes. The topics require $t_1, t_2, dots, t_n$ ( $1 le t_i le L$) minutes each. For each topic, you must decide in which lecture it should be covered. There are two scheduling restrictions:

    1.
    Each topic must be covered in a single lecture. It cannot be divided into two lectures. This reduces discontinuity between lectures.
    2.
    Topic i must be covered before topic i + 1 for all $1 le i < n$. Otherwise, students may not have the prerequisites to understand topic i + 1.

    With the above restrictions, it is sometimes necessary to have free time at the end of a lecture. If the amount of free time is at most 10 minutes, the students will be happy to leave early. However, if the amount of free time is more, they would feel that their tuition fees are wasted. Therefore, we will model the dissatisfaction index (DI) of a lecture by the formula: 

    egin{displaymath}DI = cases{0 & if $t=0$, cr
-C & if $1 le t le 10$, cr
(t-10)^2 & otherwise}
end{displaymath}

    where C is a positive integer, and t is the amount of free time at the end of a lecture. The total dissatisfaction index is the sum of the DI for each lecture.


    For this problem, you must find the minimum number of lectures that is needed to satisfy the above constraints. If there are multiple lecture schedules with the minimum number of lectures, also minimize the total dissatisfaction index.

    Input 

    The input consists of a number of cases. The first line of each case contains the integer n, or 0 if there are no more cases. The next line contains the integers L and C. These are followed by n integers $t_1, t_2, dots, t_n$.

    Output 

    For each case, print the case number, the minimum number of lectures used, and the total dissatisfaction index for the corresponding lecture schedule on three separate lines. Output a blank line between cases.

    Sample Input 

    6
    30 15
    10
    10
    10
    10
    10
    10
    10
    120 10
    80
    80
    10
    50
    30
    20
    40
    30
    120
    100
    0
    

    Sample Output 

    Case 1:
    Minimum number of lectures: 2
    Total dissatisfaction index: 0
    
    Case 2:
    Minimum number of lectures: 6
    Total dissatisfaction index: 2700
    

    Miguel A. Revilla
    1999-04-06
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 const int inf=0x3f3f3f3f;
     7 
     8 int n,l,c;
     9     int i,j,k;
    10     int cas=1,ans;
    11     int a[1005],sum[1005],dp[1005][1005];
    12 
    13 int dissatisfaction(int x)
    14 {
    15     if(x==0)
    16         return 0;
    17     else if(1<=x && x<=10)
    18         return (-c);
    19     else
    20         return (x-10)*(x-10);
    21 
    22 }
    23 
    24 int main()
    25 {
    26     
    27     while(scanf("%d",&n)!=EOF && n!=0)
    28     {
    29         sum[0]=0;
    30         scanf("%d %d",&l,&c);
    31         for(i=1;i<=n;i++)
    32         {
    33             scanf("%d",&a[i]);
    34             sum[i]=sum[i-1]+a[i];
    35         }
    36         for(i=0;i<=n;i++)
    37         {
    38             dp[i][0]=0;
    39             for(j=1;j<=n;j++)
    40                 dp[i][j]=inf;
    41         }
    42 
    43         for(i=1;dp[i-1][n]==inf;i++)
    44         {
    45             for(j=i;j<=n && sum[j]<=i*l;j++)
    46             {
    47                 for(k=j;k>=i-1;k--)
    48                 {
    49                     if(dp[i-1][k]!=inf && (sum[j]-sum[k])<=l)
    50                         dp[i][j]=min(dp[i][j],dp[i-1][k]+dissatisfaction(l-sum[j]+sum[k]));
    51                     else if(sum[j]-sum[k]>l)
    52                         break;
    53                 }
    54             }
    55         }
    56 
    57         for(i=1;i<=n;i++)
    58         {
    59             if(dp[i][n]!=inf)
    60             {
    61                 ans=i;
    62                 break;
    63             }
    64         }
    65         if(cas>1) 
    66             printf("
    ");
    67         printf("Case %d:
    Minimum number of lectures: %d
    Total dissatisfaction index: %d
    ",cas++,ans,dp[ans][n]);
    68     }
    69     return 0;
    70 }
    View Code
  • 相关阅读:
    HDU2222 自动机(学习中)
    POJ 2289(多重匹配+二分)
    POJ 1486二分图的必要边
    二分图
    2015陕西 并查集
    Hdu2680 最短路
    函数调用约定
    用01随机函数构造[a,b]整数范围随机数
    hello
    Ubuntu 16.04 install R language
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771624.html
Copyright © 2011-2022 走看看