UVA - 607 Scheduling Lectures
来源:互联网 发布:苹果mac死机 编辑:程序博客网 时间:2024/05/16 11:22
题意:给你n个课题,在给你L,C,代表一堂课的时间和一个常数,还有每个课题的时间,要求课题的顺序必须是严格的从小到大就是Ni必须在Ni+1后上,课题必须严格的在一堂课上,同时,如果在每堂课的最后如果能留有10分钟以内的时候,那么学生的不满意程序是最小的。不满意程度的计算如下所示:
D=0(如果剩下的时间是0)。
D=-c(如果剩下的时间在10分钟以内)。
D=0(如果剩下的时间是0)。
D=-c(如果剩下的时间在10分钟以内)。
D=(t-10)^2(剩下的情况) 。求安排完所有的课题需要几节课,并让不满意的程度尽量小,用num[i]代表前i个课题的最少课是多少,Cost[i]表示前i个课题的不满意程度,贪心最少的课数
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1010;const int INF = 1<<30;int n,L,C,num[MAXN],Cost[MAXN],s[MAXN];int getCost(int a){ if (a == 0) return 0; if (a >= 1 && a <= 10) return -C; return (a-10)*(a-10);}int main(){ int cas = 0; while (scanf("%d",&n) != EOF && n){ scanf("%d%d",&L,&C); memset(num,0,sizeof(num)); memset(Cost,0,sizeof(Cost)); memset(s,0,sizeof(s)); int x; for (int i = 1; i <= n; i++){ scanf("%d",&x); s[i] = s[i-1] + x; num[i] = Cost[i] = INF; for (int j = 0; j < i; j++){ //j从0开始便包括了i课题自己一节课的可能 if ((L-s[i]+s[j]) >= 0){ int ans = getCost(L-s[i]+s[j]); if (num[j] + 1 < num[i]){ num[i] = num[j] + 1; Cost[i] = Cost[j] + ans; } else if (num[j] + 1 == num[i]) Cost[i] = min(Cost[i],Cost[j]+ans); } } } if (cas) printf("\n"); printf("Case %d:\nMinimum number of lectures: %d\n", ++cas, num[n]); printf("Total dissatisfaction index: %d\n", Cost[n]); } return 0;}
- 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
- UVa 607 - Scheduling Lectures
- uva 607 Scheduling Lectures
- 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, 贪心)
- 进程与线程的一个简单解释
- 487-3279
- SAP销售订单税的确定
- opencv windows下VS配置
- RPG Maker XP游戏制作方法(五)
- UVA - 607 Scheduling Lectures
- A Smple JAX-WS Service in the CXF Distribution
- Nginx高并发负载的优化(1)
- linux线程相关函数详解
- u影苦于公开iuykiuyk裤天空
- Tomcat高并发相关配置
- 笔记3:填充图形
- Delphi 中的常用事件
- C++ Q&A