HDU 2639

简介: Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 883 Accepted Submission(s): 411 Problem Description The title of this pr
Bone Collector II

Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 883 Accepted Submission(s): 411


Problem Description
The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup" competition,you must have seem this title.If you haven't seen it before,it doesn't matter,I will give you a link:

Here is the link:http://acm.hdu.edu.cn/showproblem.php?pid=2602

Today we are not desiring the maximum value of bones,but the K-th maximum value of the bones.NOTICE that,we considerate two ways that get the same value of bones are the same.That means,it will be a strictly decreasing sequence from the 1st maximum , 2nd maximum .. to the K-th maximum.

If the total number of different values is less than K,just ouput 0.


Input
The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two integer N , V, K(N <= 100 , V <= 1000 , K <= 30)representing the number of bones and the volume of his bag and the K we need. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.


Output
One integer per line representing the K-th maximum of the total value (this number will be less than 231).


Sample Input
3
5 10 2
1 2 3 4 5
5 4 3 2 1
5 10 12
1 2 3 4 5
5 4 3 2 1
5 10 16
1 2 3 4 5
5 4 3 2 1


Sample Output
12
2

0

先全部存起来,再排序,再开一个数组遇到不同的就存起来。

#include <string.h>
#include<stdio.h>
#include<algorithm>
using namespace std; 
int f[1005][35],temp[65];
int w[105],c[105];
int main()
{
    int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,vol,kth;
	   	scanf("%d%d%d",&n,&vol,&kth);
		int i,j,k,cns;
		for(i=0;i<n;i++) 
		scanf("%d",&w[i]); 
		for(i=0;i<n;i++)  
		scanf("%d",&c[i]); 
		memset(f,0,sizeof(f));
		for(i=0;i<n;i++)
		{
			for(j=vol;j>=c[i];j--)
			{
				 cns=0;
				for(k=0;k<kth;k++)
				{  
					temp[cns++]=f[j][k];
					temp[cns++]=f[j-c[i]][k]+w[i];
				}
				sort(temp,temp+cns);
				     int p=0;
				for(k=cns-1;k>=0;k--)
				{
					if(p>=kth)   
						break;
					if(k==cns-1 || temp[k]!=temp[k+1])   
						f[j][p++]=temp[k];  
				}
			}
		} 
	      printf("%d\n",f[vol][kth-1]);
	}
	return 0;
}


目录
相关文章
|
3月前
|
缓存 NoSQL 测试技术
商品详情页高并发读:多级缓存与击穿、雪崩、穿透三件套防护实践
商品详情页是商城读流量最大的入口,大促时缓存一旦击穿、雪崩、穿透,会直接打垮数据库。本文讲清多级缓存架构(本地缓存+Redis+数据库)与三类故障的成因和防护:互斥重建、逻辑过期、布隆过滤器,并给出Java与Redis命令和五个生产踩坑。
|
3月前
|
人工智能 监控 安全
Token Plan 怎么使用?阿里云百炼 Token Plan 团队版订阅/配置/接入,获取 API Key 和 Base URL流程与排错指南
Token Plan团队版解决企业多模型使用过程中计费割裂、密钥繁多、团队权限管控困难的痛点,依托统一Credits订阅体系,兼容行业主流接口协议,打通大量开发工具。整个落地链路从订阅套餐、席位分配、获取凭证,再到代码或者第三方工具接入,流程清晰简洁。企业落地的时候需要区分团队版与个人版凭证差异,做好密钥安全、成员权限、用量监控,结合自身业务选择合适坐席档位,就可以高效构建团队级AI研发底座。
855 0
|
4月前
|
人工智能 安全 Cloud Native
云原生驱动:AI防泄密(DLP)与阿里云SASE架构深度融合及零信任实践
本文揭示内部威胁成数据泄露主因,传统DLP已失效。阿里云SASE联合固信AI Insight,融合零信任、Cloud DLP与大模型语义分析,实现秒级风险识别、动态策略闭环与合规举证,打造云原生AI防泄密新范式。(239字)
|
5月前
|
SQL 人工智能 自然语言处理
企业需要的不是会写 SQL 的 AI 问数工具,而是懂业务语义的 AI 分析搭档
只有建立在统一语义层之上的 AI 分析搭档,才能提供可信、可解释、可复用的分析能力。
|
6月前
|
存储 算法 安全
计算机理论的灵魂追问?
计算机基础理论有哪些?
790 0
|
7月前
|
应用服务中间件 文件存储 nginx
测试 NAS 容器服务恢复时的 Docker Compose 排查记录
节后恢复NAS测试环境,Jellyfin、PhotoPrism、Home Assistant容器页面异常。本文记录分层排查过程:从磁盘空间、镜像拉取、Compose状态,到挂载路径、端口连通性及Nginx反向代理配置,精准定位三处问题并修复。(239字)
|
人工智能 机器人 Serverless
探展打卡 Serverless,2025 云栖大会来了
2025 云栖大会即将于 9 月 24 日至 26 日在杭州云栖小镇盛大开幕,本次大会分别设置 Serverless 体验区与【Serverless 助力 AI Agent 开发与落地】分论坛,参会者可现场体验热门 Serverless 产品,近距离了解最新技术进展。无论是探索函数计算、Serverless 应用引擎 SAE 的创新实践,还是参与 AI Agent 开发的深度讨论,这里都将为您提供前沿洞察与实操机会。
|
12月前
|
SQL 安全 网络安全
从漏洞到攻击链:一次看懂黑客的思维链路
从漏洞到攻击链:一次看懂黑客的思维链路
1025 4
|
自然语言处理 数据可视化 数据管理
零代码平台什么意思?一文看懂无代码 vs 低代码区别与实用价值
本文解析零代码与低代码核心差异,结合虚构案例说明适用场景,帮助非技术决策者根据团队能力与业务需求,选择高效、低成本的数字化转型工具。
|
数据采集 传感器 监控
Modbus 与 MQTT 协议兼容:MyEMS 的泛在能源数据采集技术实现
MyEMS深度融合Modbus与MQTT协议,破解能源数据采集中协议碎片化、网络异构、数据孤岛等难题。通过Modbus接入95%以上工业设备,实现现场数据精准“拉取”;依托MQTT构建高效物联网传输通道,支持多源数据主动“推送”与云端集成。边缘侧采集规整,中心侧汇聚分析,形成统一、可靠、低延迟的数据流。该架构兼具高兼容性、强扩展性与低运维成本,广泛应用于工业园区、商业楼宇及集团型企业,支撑实时监控、AI分析与跨系统融合,打造泛在互联的能源数据底座,助力企业实现全面智慧能源管理。
841 6