UVA 607 Scheduling Lectures(DP)
来源:互联网 发布:苹果cms如何绑定分类 编辑:程序博客网 时间:2024/05/06 18:40
Description
You are teaching a course and must cover n ( ) topics. The length of each lecture is L ( ) minutes. The topics require ( ) 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 . 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:
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 byn integers .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
630 1510101010101010120 1080801050302040301201000
Sample Output
Case 1:Minimum number of lectures: 2Total dissatisfaction index: 0Case 2:Minimum number of lectures: 6Total dissatisfaction index: 2700
状态比较容易去想:我的做法先贪心,得到最小节数,然后DP,得到最小代价。复杂度有点高。勉强过去。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int INF = 0x3f3f3f3f;int a[1100];int dp[1010][1010];int len[1010];int n,L,C;int getdi(int t){ if(t==0) return 0; else if(t>=1&&t<=10) return -C; else return (t-10)*(t-10);}int main(){ int cas=1; while(~scanf("%d",&n)&&n) { if(cas>1) puts(""); scanf("%d%d",&L,&C); len[0]=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); len[i]=len[i-1]+a[i]; } int sum=0,ans=0; for(int i=1;i<=n;i++) { if(sum+a[i]<=L) sum+=a[i]; else { sum=a[i]; ans++; } } if(sum) ans++; CLEAR(dp,INF); dp[0][0]=0; for(int i=1;i<=n;i++) { for(int j=1;j<=min(i,ans);j++) { if(len[i]>j*L) continue; for(int p=i-1;p>=j-1;p--) { if(dp[p][j-1]==INF) continue; if(len[i]-len[p]>L) break; if(len[i]-len[p]<=L) dp[i][j]=min(dp[i][j],dp[p][j-1]+getdi(L-(len[i]-len[p]))); } } } printf("Case %d:\n",cas++); printf("Minimum number of lectures: %d\n",ans); printf("Total dissatisfaction index: %d\n",dp[n][ans]); } return 0;}
- UVA 607 Scheduling Lectures | dp
- Scheduling Lectures - UVa 607 dp
- UVA 607 Scheduling Lectures(DP)
- UVA 607 - Scheduling Lectures (线性dp)
- UVa 607 Scheduling Lectures(DP, 贪心)
- Uva 607 Scheduling Lectures (Dp+贪心)
- UVA 607-Scheduling Lectures(贪心+DP)
- uva 607 Scheduling Lectures
- UVA 607 Scheduling Lectures
- UVA - 607 Scheduling Lectures
- UVA - 607 Scheduling Lectures
- uva 607 - Scheduling Lectures
- uva 607 - Scheduling Lectures
- UVA - 607 Scheduling Lectures
- UVA - 607 Scheduling Lectures
- UVA - 607 Scheduling Lectures
- uva 607 Scheduling Lectures
- UVA 607 Scheduling Lectures
- Hadoop之——RPC通信实例
- Android 获取并显示远程图片 Picasso框架的使用(二)
- 解决android sdk 版本更新问题
- 2、Linux操作系统之操作篇-Xmanager 远程访问Linux图形化界面
- python-时间处理问题
- UVA 607 Scheduling Lectures(DP)
- FireBLE(2)——如何通过串口下载程序
- HDU 4619 Warm up 2 最大独立集
- 2-11-0
- Swift语言小结2
- LintCode-硬币排成线 III
- Android_JSON解析
- vs注释快捷键
- 【minecraft bukkit 插件开发】如何获取木牌对象,如何修改木牌内容