随笔 - 530  文章 - 0  评论 - 3  阅读 - 10098 
1
2
3
每节课的长度为 L,有N个主题,讲每个主题的时间分别是 t1,t2,t3...,
每个主题必须在一节课讲完,不能分两节课。一节课可以将多个主题讲完每节课上完有不满意度。
在所需课程数量最少的前提下,求最小不满意度。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ;
const int N =1e3+3;
 int n,a[N],T[N],f[N],L,C ;
 // f[i] = min(f[j]+ (a[j+1]+...+a[i]))
 // s[i]-s[j]<=L
  
 int cal(int t){
    if(t==0) return 0;
    else if(1<=t&&t<=10) return -C;
    else return (t-10)*(t-10);
 }
 void sov(int cas){
    memset(f,127,sizeof f);
    T[0]=f[0]=0;
     
    for(int i=1;i<=n;i++){
        T[i]=T[i-1]+1;
        f[i]=f[i-1]+cal(L-a[i]);
        int sum=a[i];
         
        for(int j=i-1;j>=0;j--){
            int tmp= f[j]+cal(L-sum);
             
            if(T[i]>T[j]+1){
                T[i]=T[j]+1;
                f[i]=tmp;
            }
            else if(T[i]==T[j]+1&&tmp<f[i]){
                f[i]=tmp;
            }
            sum+=a[j];
            if(sum>L) break;
        }      
    }
     
    cout << "Case "<<cas<<":" << endl;
    cout << "Minimum number of lectures: " << T[n] << endl;
    cout << "Total dissatisfaction index: " <<f[n] << endl;
     
 }
 signed main(){
    int cas=0;
    cin>>n;
    while(n){
        cin>>L>>C;
        for(int i=1;i<=n;i++) cin>>a[i];
        sov(++cas);
        cin>>n;
        if(n) cout<<'\n';
    }
 }

 


 

 
posted on   towboat  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示