zoukankan      html  css  js  c++  java
  • UVA607

    /*
    题意:
    每节课的长度为 L,有N个主题,讲每个主题的时间分别是 t1,t2,t3...,
    每个主题必须在一节课讲完,不能分两节课。每节课上完有不满意度。
    求最小不满意度。
    
    */ 
    
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define INF 0x3f3f3f3f
    using namespace std;
    int sum[1010],l,c;
    int a[1010];
    int dp[1010][1010];
    int get(int t)
    {
        int x=l-t;
        if(x==0) return 0;
        if(x>=1 && x<=10) return -c;
        else if(x>10) return (x-10)*(x-10);
    }
    int main()
    {
        int n,cnt=0;
        while(scanf("%d",&n)!=EOF && n)
        {
            scanf("%d%d",&l,&c);
            sum[0]=0;
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                sum[i] = sum[i-1] + a[i];
            }
            memset(dp,INF,sizeof(dp));
            for(int i=0;i<=n;i++)
                dp[i][0]=0;    
            for(int i=1;dp[i-1][n]==INF;i++)
            {
                for(int j=i;j<=n && sum[j]<=i*l ;j++)
                {
                    for(int k=j;k>=i-1;--k)
                    {
                        if(sum[j]-sum[k]<=l && dp[i-1][k] !=INF)
                            dp[i][j] = min(dp[i][j],dp[i-1][k] + get(sum[j]-sum[k]));
                        else if(sum[j]-sum[k] > l) 
                            break;
                    }
                    
                }
            }                      
            int i;
            for (i = 1; i <= n; ++i)
                if (dp[i][n] != INF)
                    break;
            if (cnt)
                printf("
    ");
            printf("Case %d:
    ", ++cnt);
            printf("Minimum number of lectures: %d
    ", i);
            printf("Total dissatisfaction index: %d
    ", dp[i][n]);
        }
        return 0;
    }
  • 相关阅读:
    hdu2328 Corporate Identity
    hdu1238 Substrings
    hdu4300 Clairewd’s message
    hdu3336 Count the string
    hdu2597 Simpsons’ Hidden Talents
    poj3080 Blue Jeans
    poj2752 Seek the Name, Seek the Fame
    poj2406 Power Strings
    hust1010 The Minimum Length
    hdu1358 Period
  • 原文地址:https://www.cnblogs.com/ember/p/4921951.html
Copyright © 2011-2022 走看看