ZOJ 3956 Course Selection System 01背包

【tips】在PyCharm中安装opencv图文版详细教程 pip如下图所示,左边的蓝色图标就是终端。点开终端后,键入命令,按下回车后就开始下载了。如果你更喜欢图形化操作,可以在 PyCharm 中直接安装:。点击右上角的 +按钮(添加包)。搜索或,点击。 阅读详情

Course Selection System

Time Limit: 1 Second      Memory Limit: 65536 KB

There are n courses in the course selection system of Marjar University. The i-th course is described by two values: happiness Hi and credit Ci. If a student selects m courses x1, x2, ..., xm, then his comfort level of the semester can be defined as follows:

$$(\sum_{i=1}^{m} H_{x_i})^2-(\sum_{i=1}^{m} H_{x_i})\times(\sum_{i=1}^{m} C_{x_i})-(\sum_{i=1}^{m} C_{x_i})^2$$

Edward, a student in Marjar University, wants to select some courses (also he can select no courses, then his comfort level is 0) to maximize his comfort level. Can you help him?

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains a integer n (1 ≤ n ≤ 500) -- the number of cources.

Each of the next n lines contains two integers Hi and Ci (1 ≤ Hi ≤ 10000, 1 ≤ Ci ≤ 100).

It is guaranteed that the sum of all n does not exceed 5000.

We kindly remind you that this problem contains large I/O file, so it's recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.

Output

For each case, you should output one integer denoting the maximum comfort.

Sample Input
2
3
10 1
5 1
2 10
2
1 10
2 10
Sample Output
191
0
Hint

For the first case, Edward should select the first and second courses.

For the second case, Edward should select no courses.


Author: WANG, Yucheng
Source: The 17th Zhejiang University Programming Contest Sponsored by TuSimple

因为c的值很小,所以以c看做重量,把h当做价值

01背包,取尽可能大的h

因为当c固定时,这个式子只需要看前面 h*h-h*c=h*(h-c)

h大于c时,肯定h越大越好

h小于c时,表达式的值必定小于零,肯定是不考虑的

#include<bits/stdc++.h>
using namespace std;
long long int dp[50005],h[505],c[505];
int main()
{
	int n,t,i,j;
	while(cin>>t)
	{
		while(t--)
		{
			scanf("%d",&n);
			long long maxx=0,now;
			memset(dp,-1,sizeof(dp));
			for(i=0;i<n;i++)
			{
				scanf("%lld %lld",&h[i],&c[i]);
			}
			dp[0]=0;
			for(i=0;i<n;i++)
			{
				for(j=50000;j>=c[i];j--)
				{
					if(dp[j-c[i]]==-1)
					continue;
					if(dp[j-c[i]]+h[i]>dp[j])
					{
						dp[j]=dp[j-c[i]]+h[i];
						now=dp[j]*dp[j]-j*dp[j]-j*j;
						if(now>maxx)
                      maxx=now;
					}

				}
			}
			printf("%lld\n",maxx);
		}

	}
	return 0;
}




YOLOv8【第十一章:视频追踪与流处理篇·第3节】匈牙利算法(Hungarian Algorithm)与 KM 算法匹配机制详解! 🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏。该专栏系统复现并梳理全网各类 YOLOv8 改进与实战案例(当前已覆盖分类 / 检测 / 分割 / 追踪 / 关键点 / OBB 检测等方向),坚持持续更新 + 深度解析,质量分长期稳定在 97 分以上,可视为当前市面上 覆盖较全、更新较快、实战导向极强 的 YOLO 改进系列内容之一。 阅读详情

相关推荐

对接萤石平台调用播放

萤石api 管理 · 萤石开放平台API文档 httpclient pom <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.2</version> </dependency> package com.ruoyi...

u011799016的博客 1782

浙大校赛- Course Selection System

There are n courses in the course selection system of Marjar University. The i-th course is described by two values: happiness Hi and credit Ci. If a student selects m courses x1, x2, …, xm, then his c

beckyUp的博客 596

从零玩转显示屏:手把手教你用Arduino驱动SPI屏幕(附引脚定义图)

本文提供了一份详尽的Arduino驱动SPI屏幕的入门指南。从SPI接口的核心引脚定义(如DC、RESET)与RGB接口的区别讲起,手把手指导硬件连接与软件库配置,并最终通过一个天气显示器实战项目,帮助读者掌握驱动SPI屏幕、显示RGB色彩内容的核心技能。

weixin_29189987的博客 136

ZOJ 3956 Course Selection System (01背包)

Course Selection System Time Limit:1 Second Memory Limit:65536 KB There arencourses in the course selection system of Marjar University. Thei-th course is described by two values: happines...

LSD20164388的博客 440

深入了解BPM及BPM业务流程管理系统

BPM 即业务流程管理,是一种以规范化的构造端到端的卓越业务流程为中心,以持续地提高组织业务绩效为目的的系统化方法。它涵盖了业务流程的整个生命周期,包括流程的设计、执行、监控、分析和优化。BPM 作为一种先进的管理方法,对于企业提高运营效率、降低成本、提升客户满意度和增强竞争力具有重要意义。BPM 流程管理系统为企业实现 BPM 提供了强大的工具和支持,而 F2BPM 流程管理平台以其先进的技术架构、丰富的功能模块、简单易用的操作界面和强大的定制能力,成为企业实现业务流程管理的理想选择。

Stone3625的博客 2959

华为防火墙主备模式工作原理

防火墙主备模式下,备墙的工作状态

weixin_67050107的博客 2146

Course Selection System(ZOJ-3956)

Problem Description There arencourses in the course selection system of Marjar University. Thei-th course is described by two values: happinessHiand creditCi. If a student selectsmcoursesx1...

Alex_McAvoy的博客 561

避坑指南:Python模拟抖音扫码登录时,那些你可能会遇到的‘Referer’和‘Token’校验问题

本文深入解析Python模拟抖音扫码登录时常见的Referer校验与Token失效问题,提供五大陷阱的解决方案。从动态fp参数生成到Referer校验策略,再到Token生命周期管理,手把手教你破解抖音登录接口的反爬机制,助力开发者高效完成自动化登录。

weixin_42573113的博客 793

Zoj 3956 Course Selection System (01背包)

Course Selection System Time Limit: 1 Second      Memory Limit: 65536 KB There are n courses in the course selection system of Marjar University. The i-th course is described by two values: ha

K键盘里的青春K 854

把慢点掰开看:在 SAP HANA 中启用 SQL 优化耗时跟踪 SqlOptTime 的实战指南

摘要:SAP HANA 性能排查中,常出现SQL查询时快时慢的现象,表面看似执行问题,实则是编译阶段耗时过长。通过SQL优化跟踪工具SqlOptStep和SqlOptTime,可精准区分编译与执行时间。SqlOptStep展示优化树变化过程,而SqlOptTime则记录各阶段耗时,帮助定位问题根源。启用SqlOptTime需配置traceprofile,建议限定特定用户以减少系统负载。实际案例显示,报表响应慢常由计算视图编译(CeQo)导致,而非执行阶段问题。解决方案包括调整计算视图展开方式或优化基础视图结

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1023

【PPS便携式移动电源】如何透彻了解便携式移动电源,仅需要十分钟阅读即可

PPS 便携式储能电源的发展前景广阔,受益于户外经济爆发、应急备灾需求提升及 “双碳” 政策支持,全球市场规模预计持续增长,2025 年出货量将达 2380 万台,未来将向大功率大容量、光充一体化、智能化方向发展,还会拓展家庭储能、移动医疗等新场景,同时钠离子电池应用、双向逆变技术升级将进一步推动行业发展。

昔时扬尘处 274

ZOJ17th校赛I题Course Selection System

题目: Course Selection System Time Limit: 1 Second      Memory Limit: 65536 KB There are n courses in the course selection system of Marjar University. The i-th course is described by two val

winnerCLAY的博客 946

使用 MATLAB/Simulink + Simscape Electrical + SimPowerSystems + Stateflow,构建一个多能互补微电网系统的动态响应仿真模型

本文详细介绍了使用MATLAB/Simulink构建多能互补微电网动态响应仿真模型的方法。文章从系统架构设计入手,包含光伏、风电、柴油发电机、锂电池储能等多种组件,重点讲解了建模过程、控制策略(下垂控制、PLL、SOC管理)和模式切换逻辑(Stateflow)。通过四种典型场景(负荷突增、光伏出力骤降、并网/孤岛切换、电动机启动)的仿真分析,验证了微电网在动态响应中的关键性能指标,并提出了高可靠性设计建议。该模型为微电网的稳定性分析和优化设计提供了有效工具,特别强调了储能系统在快速功率支撑中的重要作用。

amy_mhd的博客 164

ZOJ 3956 Course Selection System(01背包)

Course Selection System Time Limit: 1 Second      Memory Limit: 65536 KB There are n courses in the course selection system of Marjar University. The i-th course is described by two values: ha

CillyB的博客 959

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

ZOJ 3956 Course Selection System 01背包

Course Selection System Time Limit: 1 Second      Memory Limit: 65536 KB There are n courses in the course selection system of Marjar University. The i-th course is described by two values:

计算机技术 1206

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

ZOJ-3956 Course Selection System(01背包)

题意 有 nnn 门课程,每门课程都有它的快乐值 HiHiH_i,学分 CiCiC_i。现在选择若干门课程(可不选),它们的舒适值的结果满足下式: (∑imHxi)2−∑imHxi∑imCxi−(∑imCxi)2(∑imHxi)2−∑imHxi∑imCxi−(∑imCxi)2(\displaystyle\sum_i^mHx_i)^2-\displaystyle\sum_i^mHx_i\disp...

Paulliant的博客 337

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

【ZOJ - 3956】Course Selection System(01背包)

题干: There arencourses in the course selection system of Marjar University. Thei-th course is described by two values: happinessHiand creditCi. If a student selectsmcoursesx1,x2, ...,xm, th...

xuanweiace的博客 442

ZOJ 3956 Course Selection System 01背包变形

题目链接    题意: 给你n个hi, ci,问你怎样拿才能让你 使上面式子最大。   思路: 根据上面的式子我们可知,对于一个C值当hi越大,则上面的式子才可能更大一些,又因为题目中C的值很小最多 50000,所以我们可以以C为背包容量 c[i]为体积h为价值进行01背包,然后维护一下最大值. 真的是很巧妙的问法,当时有想过dp,想到了背包可是没有明确怎么背,,,哎 orz #i

Marcus-Bao的个人主页 1052

ZOJ 3956 Course Selection System(01背包变形)

Course Selection System Time Limit: 1 Second      Memory Limit: 65536 KB There are n courses in the course selection system of Marjar University. The i-th course is described by two values:

No Rain,No L'Arc~en~Ciel 375

ZOJ 3956 Course Selection System 【 思维 + 01背包 】

传送门 //题意:就是选择很多对然后左边的相加是H(x), 右边相加是C(x), 最后要使得题目中给出的那个公式算出来的答案要最大. //思路: 我们观察可以发现C的值比较小, 只有100, n又只有500, 所以(求和)C最大只有5e4, 所以我们可以找出对于每一个容量(1-5e4的每一个数看作是一个容量), 它对应的最大值是多少, 也就是类似于01背包了, 所以做一次01背包算出对应的最大

Anxdada -- 我等风来也等你 708

ZOJ 3956——Course Selection System(01背包)

题目链接: 因为c的值很小,所以以c看做重量,把h当做价值 01背包,取尽可能大的h 因为当c固定时,这个式子只需要看前面 h*h-h*c=h*(h-c) h大于c时,肯定h越大越好 h小于c时,表达式的值必定小于零,肯定是不考虑的 #include &lt;cstdio&gt; #include &lt;cmath&gt; #include&lt;vector&gt; #inclu...

ZMST的博客 242

ZOJ - 3956 Course Selection System 01背包

https://vjudge.net/problem/ZOJ-3956 题意:就是让你求这个式子的最大值。要选的话h[i]和c[i]同时加,不选的话就都不加。 做法:看c[i]范围,很小是吧,考虑一下sigma_c[i]  max=5e4,n范围完全够01背包的复杂度。 然后就01背包了。。 /// .-~~~~~~~~~-._

twh233的算法blog 282

ZOJ 3956 Course Selection System [01背包]

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 题意:就是给你Hi,Ci的值,问怎么取使得下面那个式子的值最大:    理解:当时做了好久以为是贪心>_<.后来看别人的题解发现是01背包,现在学了01背包以后看就好理解多了。 因为每个值都是取或不取,所以容易想到是01背包。而且Hi的范围是[1,...

weixin_33979363的博客 119

Zoj 3956 Course Selection System【01背包】

Course Selection System Time Limit: 1 Second      Memory Limit: 65536 KB There are n courses in the course selection system of Marjar University. The i-th course is described by two values

mengxiang000000 408

ZOJ-3956 Course Selection System,01背包!

Course Selection System   比赛的时候最后20分钟想到了是01背包,奈何没时间推出怎么背。   题意:n门课程,每门课程都有一个h值和c值,现在给出一个happy的定义,所选的课程的h的和H,c的和C,happy=H^2-C^2-HC。求happy的最大值。  思路:开始以为是贪心,但感觉没有贪心这么简单,在这个问题中每门课程都有选或不选两种情况,很容易就想到01

NYIST_TC_LYQ的博客 573

ZOJ-3956 Course Selection System(01背包)

题意:让你选定m,求公式所得的最大结果。 思路:我们选的m的前提肯定是尽量使得减数大、被减数小。那么我们可以枚举∑Ci,求得最大Hi。那么这个就转化的和01背包问题差不多了。 代码: #include #include #include #include using namespace std; typedef long long ll; const int MOD = 1e9+7; c

huatian5的博客 394
上一篇: 蓝桥2016省赛 剪邮票
下一篇: ZOJ 3954 Seven-Segment Display
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值