P2392 kkksc03考前临时抱佛脚

题解

01背包,类似于这道题,相似度99.999999%:

01-背包 P2663 越越的组队

 
一共有4科,每科的时间独立,然后每一科做一遍 P2663越越的组队,时间之和累加得到答案
 
考虑复习每一科的最短时间
由于可以左右脑并用,所以把题目简化一下就是把所有题目分成两组,取时间最长的一组作为答案,但是要使得时间最长的一组它的时间尽量短
我们知道两组数值越接近,肯定就是最优答案了
 

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue> using namespace std; typedef long long ll; inline int read()
{
int ans=;
char last=' ',ch=getchar();
while(ch<''||ch>'') last=' ',ch=getchar();
while(ch>=''&&ch<='') ans=ans*+ch-'',ch=getchar();
if(last=='-') ans=-ans;
return ans;
} int cnt[],s[];
int f[];
int ans=,tot=,ave=; int main()
{
for(int i=;i<=;i++) cnt[i]=read();
for(int t=;t<=;t++){
memset(s,,sizeof(s));
memset(f,,sizeof(f));
tot=,ave=;
for(int i=;i<=cnt[t];i++) s[i]=read(),tot+=s[i];
ave=tot/;
for(int i=;i<=cnt[t];i++)
for(int j=ave;j>=s[i];j--)
f[j]=max(f[j],f[j-s[i]]+s[i]);
ans+=(tot-f[ave]);
}
printf("%d\n",ans); return ;
}

01背包---P2392 kkksc03考前临时抱佛脚的更多相关文章

  1. 洛谷 P2392 kkksc03考前临时抱佛脚

    P2392 kkksc03考前临时抱佛脚 题目背景 kkksc03的大学生活非常的颓废,平时根本不学习.但是,临近期末考试,他必须要开始抱佛脚,以求不挂科. 题目描述 这次期末考试,kkksc03需要 ...

  2. 洛谷 P2392 kkksc03考前临时抱佛脚, dp / 深搜

    题目链接 P2392 kkksc03考前临时抱佛脚 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题目 dp代码 #include <iostream> #includ ...

  3. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  4. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  5. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  6. 51nod1085(01背包)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...

  7. *HDU3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)

    题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...

  9. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

随机推荐

  1. 跨平台打开一个URL的方法

    unit u_urlOpen; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System ...

  2. 参数化查询防止Sql注入

    拼接sql语句会造成sql注入,注入演示 namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() ...

  3. MySQL详细知识点总结

    1 Windows服务 -- 启动MySQL net start mysql -- 创建Windows服务 sc create mysql binPath= mysqld_bin_path(注意:等号 ...

  4. Linux赋予root权限

    按照帖子都一一尝试了下 https://blog.csdn.net/yajie_china/article/details/80636783 首先增加用户和给新用户创建密码,都不用说 用useradd ...

  5. nomn文件分析

    #encoding=gbk import os import re import math from os import path ''' 手动输入文件nmon文件路径,要截取的开始时间,结束时间 ' ...

  6. Hive运行引擎Tez的安装

    简介 Tez是Apache开源的支持DAG作业的计算框架,它直接源于MapReduce框架,核心思想是将Map和Reduce两个操作进一步拆分,即Map被拆分成Input.Processor.Sort ...

  7. 【基础数位DP-模板】HDU-2089-不要62

    不要62 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

  8. spring-mybatis+spring整合

    整合之前回忆一下spring和mybatis分别做了什么: spring 通过注解/xml配置,实现AOP和DI DI: 接口实现类中, 将接口私有化,从容器中读取,而不是new一个 UserDao ...

  9. 码云 VS首次提交代码报错:failed to push some refs to 'https://gitee.com/Liu_Cabbage/ASP.NET-MVC-QQ-Connect.git'

    打开命令提示符: 执行合并命令: git pull --rebase origin master 最后总结: 1.多为第一次提交代码,本地和码云仓库不一致,README.md文件不在本地代码目录中 2 ...

  10. informix创建同义词

    搜索词条 1.informix不同主机的数据库同义词创建? 2.informix怎么实现跨服务器数据抽取? 3.informix 数据库跨库访问的配置?https://blog.csdn.net/Da ...