UVA - 607 Scheduling Lectures
来源:互联网 发布:淘宝v任务 编辑:程序博客网 时间:2024/05/16 04:39
题目大意:给出课题数n,以及每堂课的时间l,以及常数c,然后是n个课题所需要的时间。
问题1:最少需要几节课时可以讲所有的课题讲完,并且课题的顺序不能调换,一个课题不能分在两节课讲。
问题2:在用的课时最少的情况下,如何让同学们的不满意度最低,不满意度的计算是根据课时的剩余时间t计算的,
解题思路:问题1可以用贪心的方法, 问题2用记忆化搜索。
#include <cstdio>#include <algorithm>#include <cstring>#include <climits>using namespace std;int L, C, t[1010], DP[1010][1010], vis[1010][1010];int DI(int time) {if (time == 0)return 0;else if(time <= 10)return -C;elsereturn (time - 10) * (time - 10);}int solve(int x, int y) {if (x == 0)return y ? INT_MAX : 0;if (vis[x][y])return DP[x][y];DP[x][y] = INT_MAX;int sum = 0;for (int i = y; i > 0; i--) {sum += t[i];if (sum > L)break;int rev = solve(x - 1, i - 1);if (rev != INT_MAX)DP[x][y] = min(rev + DI(L - sum), DP[x][y]);}vis[x][y] = 1;return DP[x][y];}int main() {int n, kase = 0;while (scanf("%d", &n), n) {int cnt = 1, sum = 0;scanf("%d%d", &L, &C);for (int i = 1; i <= n; i++) {scanf("%d", &t[i]);sum += t[i];if (sum > L) {cnt++;sum = t[i];}}memset(vis, 0, sizeof(vis));if (kase)printf("\n");printf("Case %d:\n", ++kase);printf("Minimum number of lectures: %d\n", cnt); printf("Total dissatisfaction index: %d\n", solve(cnt, n));}return 0;}
0 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, 贪心)
- 为什么要内存对齐 Data alignment: Straighten up and fly right
- JQuery Easy Ui dataGrid 数据表格
- 9->oracle dump日志文件和trc诊断文件
- JSP的九个内置对象
- 基于Arcgis for Js的web GIS数据在线采集简介
- UVA - 607 Scheduling Lectures
- CSDN-markdown语法之如何插入图片
- 银行家算法的C语言实现
- 自定义属性
- 黑马程序员------java基础----I/O流(一)
- Swift微信分享
- UVA - 10604 Chemical Reaction
- Java war打包和解压命令
- iOS企业ipa(299)证书制作、打包发布全流程(亲测,成功)