uva 607 Scheduling Lectures
2017-02-14 14:28
330 查看
原题:
You are teaching a course and must cover n (1 ≤ n ≤ 1000) topics. The length of each lecture is L (1 ≤ L ≤ 500) minutes. The topics require t 1 ,t 2 ,…,t n (1 ≤ t i ≤ 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 ≤ 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:
DI =
{
0 if t = 0,
−C if 1 ≤ t ≤ 10,
(t − 10)^ 2 otherwise,
}
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 ,…,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
中文:
首先给你一个数n表示有n个主题,
然后给你一个两个数,L和C。分别表示一节课的时间,和学生的满意程度。
接下来是n个数,表示每个主题需要花费的时间。
现在问你,用最少的课程把所有主题全都讲完,而且要按照顺序讲,不允许拖堂。如果一节课时间结束剩下超过10分钟,学生会不满意,不满意的程度为(10-t)^2,t为剩下的时间。如果剩下的时间小于10,学生会很高兴,高兴指数为C。
最后问你最少的讲课数量和最小学生不满意指数。
思路:
此题和uva 662是一个套路
状态转移方程是
此题代码不太好布置,比较恶心
You are teaching a course and must cover n (1 ≤ n ≤ 1000) topics. The length of each lecture is L (1 ≤ L ≤ 500) minutes. The topics require t 1 ,t 2 ,…,t n (1 ≤ t i ≤ 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 ≤ 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:
DI =
{
0 if t = 0,
−C if 1 ≤ t ≤ 10,
(t − 10)^ 2 otherwise,
}
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 ,…,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
中文:
首先给你一个数n表示有n个主题,
然后给你一个两个数,L和C。分别表示一节课的时间,和学生的满意程度。
接下来是n个数,表示每个主题需要花费的时间。
现在问你,用最少的课程把所有主题全都讲完,而且要按照顺序讲,不允许拖堂。如果一节课时间结束剩下超过10分钟,学生会不满意,不满意的程度为(10-t)^2,t为剩下的时间。如果剩下的时间小于10,学生会很高兴,高兴指数为C。
最后问你最少的讲课数量和最小学生不满意指数。
#include<bits/stdc++.h> using namespace std; int dp[1001][1001]; int topic; int sum[1001]; int L,C; int solve(int tmp) { int res=L-tmp; if(res==0) return 0; if(res<=10) return -C; return (res-10)*(res-10); } int main() { ios::sync_with_stdio(false); int n,t=0; while(cin>>n,n) { cin>>L>>C; memset(sum,0,sizeof(sum)); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { cin>>topic; sum[i]=topic+sum[i-1]; } for(int i=0;i<=n;i++) { for(int j=1;j<=n;j++) dp[i][j]=INT_MAX; dp[i][0]=0; } for(int i=1;i<=n||dp[i-1] ==INT_MAX;i++) { for(int j=i;j<=n;j++) { if(sum[j]>i*L) break; for(int k=j;k>=i-1&&sum[j]-sum[k]<=L;k--) { int res=sum[j]-sum[k]; if(res<=L&&dp[i-1][k]!=INT_MAX) dp[i][j]=min(dp[i][j],dp[i-1][k]+solve(res)); } } } int ind; for(int i=1;i<=n;i++) { if(dp[i] !=INT_MAX) { ind=i; break; } } if(t) cout<<endl; cout<<"Case "<<++t<<":"<<endl; cout<<"Minimum number of lectures: "<<ind<<endl; cout<<"Total dissatisfaction index: "<<dp[ind] <<endl; } return 0; }
思路:
此题和uva 662是一个套路
状态转移方程是
dp[i][j]=min(dp[i][j], dp[i-1][k]+(sum[j]-sum[k]-L-10)^2 当L-(sum[j]-sum[k])大于10 dp[i-1][k]-C 当L-(sum[j]-sum[k])小于10 dp[i-1][k]+0 等于0 k∈[i-1,j] 其中dp[i][j]表示前i堂课讲解j个主题的最少不满意度
此题代码不太好布置,比较恶心
相关文章推荐
- UVA - 607 Scheduling Lectures
- UVA 607 Scheduling Lectures(DP)
- uva_607 - Scheduling Lectures( 贪心+DP )
- uva 607 记忆化搜索
- UVA 607-Scheduling Lectures(贪心+DP)
- UVA 607 Fast Food
- UVA 607 Scheduling Lectures
- Scheduling Lectures - UVa 607 dp
- UVA - 607 Scheduling Lectures
- UVA - 607 Scheduling Lectures(贪心+记忆化搜索)
- uva 607 Scheduling Lectures
- uva 607(DP+贪心)
- UVA - 607 Scheduling Lectures
- uva 607 - Scheduling Lectures
- UVA 607 Scheduling Lectures
- UVA - 607(简单dp,先用贪心确定最大,限定状态)
- UVA - 607 Scheduling Lectures
- uva 607 - Scheduling Lectures
- 递推DP UVA 607 Scheduling Lectures
- UVA607