ZOJ 3703 Happy Programming Contest(0-1背包)

华为HCIP大数据备考实战:从题库精析到834分通关策略 本文详细介绍了华为HCIP大数据认证考试的备考策略,包括题库精析、重点章节突破和考场实战经验。作者以834分的高分通过考试,分享了官方教材的三遍阅读法、自建题库技巧以及各章节核心知识点,帮助考生高效备考并顺利通关。 阅读详情

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703


Happy Programming Contest

Time Limit: 2 Seconds      Memory Limit: 65536 KB

In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color for each problem they solved. Since the girl would prefer pink balloon rather than black balloon, each color is assigned a value to measure its attractiveness. Usually, the boy is good at programming while the girl is charming. The boy wishes to solve problems as many as possible. However, the girl cares more about the lovely balloons. Of course, the boy's primary goal is to make the girl happy rather than win a prize in the contest.

Suppose for each problem, the boy already knows how much time he needs to solve it. Please help him make a plan to solve these problems in strategic order so that he can maximize the total attractiveness value of balloons they get before the contest ends. Under this condition, he wants to solve problems as many as possible. If there are many ways to achieve this goal, he needs to minimize the total penalty time. The penalty time of a problem is equal to the submission time of the correct solution. We assume that the boy is so clever that he always submit the correct solution.

Input

The first line of input is an integer N (N < 50) indicating the number of test cases. For each case, first there is a line containing 2 integers T (T <= 1000) and n (n <= 50) indicating the contest length and the number of problems. The next line contains n integers and the i-th integer ti (ti <= 1000) represents the time needed to solve the ith problem. Finally, there is another line containing n integers and the i-th integer vi (vi <= 1000) represents the attractiveness value of the i-th problem. Time is measured in minutes.

Output

For each case, output a single line containing 3 integers in this order: the total attractiveness value, the number of problems solved, the total penalty time. The 3 integers should be separated by a space.

Sample Input
2
300 10
10 10 10 10 10 10 10 10 10 10
1 2 3 4 5 6 7 8 9 10
300 10
301 301 301 301 301 301 301 301 301 301
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Sample Output
55 10 550
0 0 0


思路:0-1背包


<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1010;
int value[maxn],a[maxn],fv[maxn];
int vis[55][maxn];
int order[55];
int main()
{
    int N,length,n;
    cin>>N;
    while(N--)
    {
        int time=0,sumtime=0,numbers=0;
        memset(vis,0,sizeof(vis));
        memset(fv,0,sizeof(fv));
        cin>>length>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=1;i<=n;i++)cin>>value[i];
        for(int i=1;i<=n;i++)
        {
           for(int j=length;j>=a[i];j--)
           {
               if(fv[j]<fv[j-a[i]]+value[i])
               {
                   fv[j]=fv[j-a[i]]+value[i];
                   vis[i][j]=1;
               }
           }
        }
        int cnt=0;
        int i=n;
        int j=length;
        for(;i>0;i--)
        {
            if(vis[i][j]==1)
            {
                order[cnt++]=a[i];
                j -= a[i];
            }
        }
        sort(order,order+cnt);
        for(int i=0;i<cnt;i++)
        {
            time +=order[i];
            sumtime +=time;
        }
        cout<<fv[length]<< " " << cnt << " " << sumtime << endl;
    }
    return 0;
}</span>



纯C语言实现的Luhn算法(信用卡校验位):详解与示例 在本文中,我们详细介绍了如何使用纯C语言实现Luhn算法,并提供了一些示例代码。用于检查任意长度的数字字符串的有效性,用于计算给定数字字符串的校验位字符。我们还提供了一个简单的“main”C程序,用于在命令行上接受一个或多个数字字符串,并计算它们的校验位字符。通过阅读本文和理解示例代码,我们希望读者能够更好地理解Luhn算法的工作原理,并能够在自己的项目中应用这种算法。 阅读详情

相关推荐

Depth Anything 3实战:如何用DINOv2 Transformer一键生成3D高斯点云?

本文详细介绍了Depth Anything 3(DA3)模型如何利用DINOv2 Transformer架构,实现从单张或多视角图像一键生成高质量3D高斯点云。DA3通过统一的深度-射线表示和自适应注意力机制,简化了传统复杂的3D重建流程,并可直接微调用于3D高斯渲染,为图形学、CV和内容创作领域提供了高效的端到端解决方案。

postgres8guard的博客 722

ZOJ 3703 Happy Programming Contest 0-1背包 DP

ZOJ 3703 Happy Programming Contest题目描述:  题目链接:ZOJ 3703 Happy Programming Contest题目大意:  这是一道虐狗的题目。讲的是一对情侣在赛码场上,每道题对应不同颜色的气球,不同的气球对妹子的吸引力不同。在已知程序员做每道题所需的时间、比赛总时长以及每一个气球对妹子的吸引值。求在能力和时间允许的前提下,得到的气球对妹子

Running Boy的AC Dream 961

ENSP实验一:防火墙基础配置

配置client(内网)、FTP Server(外网)的IP地址。进入防火墙,输入密码:默认为admin@123。

Carohuan的博客 1万+

zoj 3703(背包)

简单的背包问题, 算是一种多重的吧。 解题的关键在于,要控制最后所用的时间最少,所以在程序的最开始应该先将 输入的各种题目 以时间升序排列, 然后就可以保证每次都以时间小的优先选, 这样就可以保证最后相同的吸引值和解题数的情况下所话的时间最少。   Happy Programming ContestTime Limit: 2 Seconds      Memory Limit: 65536 ...

weixin_34362790的博客 184

路径规划:D*Lite寻路算法详解

D*Lite详解目录

mkr67n的博客 2万+

nginx配置视频流加密防盗链(一)安装nginx插件

前段时间研究了一下视频流的简单加密防盗链,参考了很多文章,最后总算搞出来了。现在自己总结了一下。

u013294657的博客 1864

zoj3703

Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 KB In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving ea

野生的声威的专栏 594

CVE-2025-25249漏洞深度解析:FortiOS认证绕过与实战缓解

远程代码执行(RCE)是网络安全中最危险的漏洞类型之一,其核心往往源于认证机制失效或内存安全缺陷。CVE-2025-25249正属于此类高危漏洞——它不依赖用户凭证,也不需要交互触发,而是通过超长HTTP头(如X-Forwarded-For)引发内存越界写入,直接绕过FortiOS和FortiSwitchManager的完整认证流程。该漏洞影响广泛、CVSS评分高达9.8,凸显了嵌入式设备在HTTP协议栈实现中的深层风险。在企业网络中,FortiGate等设备常作为边界守门人,一旦失陷将导致root级控制权

weixin_33694620的博客 523

ZOJ 3703 Happy Programming Contest 01背包+记录路径

In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color f

富士山下 429

【unity游戏开发入门到精通——通用篇】Post Processing 后处理插件Post-process Volume 和 Volume最全基础使用说明

之前我已经实现了不少后处理功能,本文其实就是将他们归类整理,以便更好的查找和理解。在Unity中,后处理(Post-Processing)是在相机所捕捉的图像上应用一些特殊效果的过程,后处理会让图像视觉效果更好(前提是做的好)。这些效果的范围有非常细微的颜色调整,也包括整体的美术风格的大修,可以让场景看起来更加真实或风格化,或者只是变得更好看。就像我们都会用手机拍照,但很多时候我们拍的原始的相片都打不到我们想要的效果。比如照片可能亮度不够,颜色不饱和或者对比度不好等。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 7894

Linux下搭建简易的HTTP服务器完成图片显示

篇文章作为Linux下socket(TCP)网络编程的练习,使用C语言代码搭建一个简单的HTTP服务器,完成与浏览器之间的交互,最终在浏览器上显示一张图片;通过这个例子可以巩固socket里多线程使用,也可以方便学习了解HTTP协议。

2587

ZOJ 3703 Happy Programming Contest

In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color f

本博停更 新博客:bugnull.com 560

Python爬虫实战:高效爬取中国版权登记数据

本文将详细介绍如何使用Python最新技术栈构建一个高效、稳定的中国版权登记数据爬虫系统。我们将使用Playwright+Asyncio实现无头浏览器自动化,结合Redis分布式任务队列和MongoDB数据存储,打造一个能够应对反爬机制的企业级数据采集方案。文章包含完整代码实现、性能优化技巧以及法律合规建议,帮助开发者快速掌握大规模数据采集的核心技术。本文详细介绍了2024年使用Python最新技术栈构建中国版权登记数据爬虫的完整方案。基于Playwright的无头浏览器自动化。

2201_76125261的博客 1897

ZOJ 3703 Happy Programming Contest(贪心+0/1背包)

首先要对每个问题按照所用时间排序,才能保证出来的惩罚时间最小 用一个dp数组保存在j时间解决问题i所能得到的attractiveness最大值 用一个solcnt数组保存解决的问题数量 用一个preTime数组保存当前问题的提交时间 用一个peanlSum保存在j时间解决问题i所用的惩罚时间总和 这样就可以DP了 比赛的时候用的一维数组怎么都过不了,赛后用了二维数组才过了 #incl

蚂蚁大战大象 1130

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

ZOJ 3703 Happy Programming Contest (0-1背包,稍微加点处理)

先按做完题目的时间排序,在确定自己要做哪些题后,先做时间短的,这样能保证等的时间是最短的,在这里,能保证罚时会是最少的。然后0-1背包,0-1背包时先只管价值最大,在背包完后当价值一样时,再管题目做的多,题目数量一样时再管罚时少。 贴代码,代码中有注释: View Code 1 #include <cstdio> 2 #include <cstring> ...

weixin_30952103的博客 101

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

01背包好题 ZOJ3703 Happy Programming Contest

是浙大校赛上的一道题。 题意:给你总时间,一些题,每个题给你所花时间,吸引力值。然后问你在总时间内,选取一种A题方案,使获得的吸引力值最大,如果有多种,则选择题数较多的,如果有多种,选择罚时较少的。 本题重点就是后面的几种比较关系;如果单看第一个条件,就是裸的01背包,但是怎么处理剩下的2个条件呢,也就是在状态转移中加入一些条件: f[v]=max{f[v],f[v-c[i]]+w[i]}

Hhaile的专栏 1127

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ZOJ3703 Happy Programming Contest

Happy Programming Contest Time Limit: 2 Seconds      Memory Limit: 65536 KB In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students lovin

Jelly_acm的博客 389

Happy Programming Contest zoj3703 dp

Description In Zhejiang University Programming Contest, a team is called “couple team” if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with un

xtulollipop 611

GD25Q80E SPI NOR Flash调试实战:从命令时序到STM32 QSPI驱动

SPI协议是嵌入式系统中最常用的串行通信接口之一,而NOR Flash作为低成本、大容量的外部存储方案,在固件升级、参数存储和代码执行等场景中扮演着重要角色。SPI NOR Flash的操作并非简单的读写,其命令时序、状态寄存器轮询、页编程边界和扇区擦除粒度等细节,往往决定一次调试的成败。GD25Q80E作为典型的25Q系列芯片,集成了标准SPI与四线QSPI模式,适合用来理解NOR Flash的完整工作机制。本文从SPI基础时序出发,结合STM32硬件QSPI外设,梳理了写使能、WIP位轮询、页编程越界、

weixin_33863087的博客 335

ZOJ - 3703 Happy Programming Contest

ZOJ - 3703 思路: 背包dp 为了使最后的罚时最少,先按做题所需时间排序 运算符重载方便背包转移。 代码: #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define LL long long #define pb push_back ...

weixin_34236497的博客 85

ZOJ 3703 Happy Programming Contest(01背包的灵活运用)

一道模拟刷题的题: 输出能够获得的最高的分值;如果有相同的,输出做题数量多的;如果还有相同的,输出罚时少的。 /* Problem : Status : By wf, */ #include "algorithm" #include "iostream" #include "cstring" #include "cstdio" #include "st...

anxianxia1695的博客 164

ZOJ 3703 Happy Programming Contest

In Zhejiang University Programming Contest, a team is called "couple team" if it consists of only two students loving each other. In the contest, the team will get a lovely balloon with unique color f

Occult 626
上一篇: ZOJ 1425 Crossed Matchings(动态规划)
下一篇: HDU 1097 A hard puzzle(简单快速幂)
hellohelloC
博客等级 码龄12年 15粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值