栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1183 Scheduling Lectures

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1183 Scheduling Lectures

#include <cstdio>#include <algorithm>#include <memory.h>using namespace std;const int MAX = 1001;int dp[MAX][MAX];int t[MAX], sum[MAX];int n, L, C;int S(int x, int y){return sum[y] - sum[x - 1];}int DI(int x, int y){int t = L - S(x, y);if(t == 0)return 0;else if(t <= 10)return -C;else return (t - 10) * (t - 10);}int main(int argc, char const *argv[]){int N;scanf("%d", &N);for(int tc = 1; tc <= N; ++tc){scanf("%d", &n);int caseno = 1;while(n){scanf("%d%d", &L, &C);for(int i = 1; i <= n; ++i){scanf("%d", &t[i]);sum[i] = sum[i - 1] + t[i];}int M = 1, s = 0;memset(dp, 0x6f, sizeof(dp));for(int i = 1; i <= n; ++i){s += t[i];if(s > L){s = t[i];++M;}}dp[0][0] = 0;for(int i = 1; i <= M; ++i){for(int j = 1; j <= n; ++j)for(int k = j - 1; k >= 0 && S(k + 1, j) <= L; --k){dp[i][j] = min(dp[i][j], dp[i - 1][k] + DI(k + 1, j));}}printf("Case %d:nnMinimum number of lectures: %dnTotal dissatisfaction index: %dn", caseno++, M, dp[M][n]);scanf("%d", &n);if(n){printf("n");}}if(tc != N){printf("n");}}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379595.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号