hdu 2660 Accepted Necklace

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=2660  

Accepted Necklace

Description

I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won't accept a necklace which is too heavy. Given the value and the weight of each precious stone, please help me find out the most valuable necklace my mother will accept.

Input

The first line of input is the number of cases. 
For each case, the first line contains two integers N (N <= 20), the total number of stones, and K (K <= N), the exact number of stones to make a necklace. 
Then N lines follow, each containing two integers: a (a<=1000), representing the value of each precious stone, and b (b<=1000), its weight. 
The last line of each case contains an integer W, the maximum weight my mother will accept, W <= 1000. 

Output

For each case, output the highest possible value of the necklace.

Sample Input

1
2 1
1 1
1 1
3

Sample Output

1

dfs。。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
using std::max;
using std::sort;
using std::pair;
using std::swap;
using std::queue;
using std::multiset;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr, val) memset(arr, val, sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = 30;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ull;
struct Node {
	int v, w;
}A[N];
bool vis[N];
int W, K, n, ans;
void dfs(int cur, int w, int v, int tot) {
	if (tot == K) {
		ans = max(ans, v);
		return;
	}
	for (int i = cur; i < n; i++) {
		if (!vis[i] && tot + 1 <= K && w + A[i].w <= W) {
			vis[i] = true;
			dfs(i + 1, w + A[i].w, v + A[i].v, tot + 1);
			vis[i] = false;
		}
	}
}
int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w+", stdout);
#endif
	int t;
	scanf("%d", &t);
	while (t--) {
		ans = -INF;
		scanf("%d %d", &n, &K);
		rep(i, n) {
			vis[i] = false;
			scanf("%d %d", &A[i].v, &A[i].w);
		}
		scanf("%d", &W);
		dfs(0, 0, 0, 0);
		printf("%d\n", ans);
	}
	return 0;
}

转载于:https://www.cnblogs.com/GadyPu/p/4889455.html

Qt入门教程【数据类型篇】数值类型 Qt中的数值类型 阅读详情

相关推荐

STM32F103C8T6用官方bootloader实现IAP升级操作方法

在使用STM32F103C8T6单片机IAP功能时,可以自己写bootloader程序,也可以使用官方bootloader文件。下面说一下使用官方bootloader的使用方法。 首先下载官方bootloader文件 目前使用的是这个版本,打开文件夹,选择适合自己编译器的工程。 目前使用的是keil,所以打开MDK-ARM文件夹 打开IAP工程 打开后根据自己的单片机型号,对工程进行简单的修...

HXYDJ的博客 1万+

ACM-DFS之Accepted Necklace——hdu2660

ACM DFS Accepted Necklace hdu2660

继续激情,继续奋斗。 1807

DOORS需求管理实战:从汽车设计案例看模块化需求拆分技巧

本文通过一个汽车设计实战案例,深入解析了如何利用DOORS进行模块化需求拆分与管理。从捕获原始用户需求到精炼为可追踪的系统需求,再到按子系统(如自动驾驶)进行模块化拆分,文章详细展示了构建需求骨架、建立可追溯性以及实施变更控制的完整流程,帮助团队在复杂系统工程中实现从混沌到秩序的高效协同。

ww90123的博客 252

杭电 HDU 2660 Accepted Necklace

http://acm.hdu.edu.cn/showproblem.php?pid=2660 Accepted Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2220    Accepted Submis

蚕豆儿 1268

深度学习的卷积神经网络的煤矸石识别

在本博文中,我们提出了一种基于深度学习的煤矸石检测与识别系统,该系统采用YOLOv8算法对煤矸石进行检测和识别,实现对图片中的煤矸石进行准确识别。1.项目需求对煤矸石进行检测与识别,系统将识别出图片中的克服小块煤矸石漏检的缺陷。 2.项目实现 通过调研,本项目最终使用yolov8模型作为目标检测的模型, YOLOv8 旨在快速、准确且易使用,使其成为广泛的物体检测、图像分割和图像分类任务的极佳选择。 1.数据集:格式为jpg的3091张煤矸石图片2.YOLOv8环境配置yolo检测网络包括24个卷积层

2201_75355700的博客 796

概述DeepLab系列(deeplab v1, deeplab v2, deeplab v3, deeplab v3+)

前言:图像分割是指像素级别的图像识别,即标注出图像中每个像素所属的对象类别。 语义分割更注重类别之间的区分,而实例分割更注重个体之间的区别。 DeepLab是由Google团队提出的一系列图像分割算法。 DeepLab v1 (2014年) Paper (ICLR 2015) Code 创新点: 空洞卷积(Atrous Conv); <解决编码过程中信号不断被下采样,细节丢失的问题> 全连接条件随机场(Fully-connected Conditional Random Field)。

ZSH12345678900的博客 5542

hdu 2660 Accepted Necklace (二维01背包)

Accepted Necklace Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 25   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Geor

天亮说晚安 2268

组态王通过以太网与西门子S7-200 SMART PLC通讯案例详解

通过以上步骤,我们成功实现了组态王与西门子S7-200 SMART PLC的以太网通讯。这一技术不仅提高了工业自动化系统的灵活性和可靠性,还为初学者提供了一个实用的学习案例。希望本文能帮助您快速掌握组态王与西门子S7-200 SMART PLC的通讯技术。如有任何疑问,欢迎留言讨论!

2401_88785500的博客 2018

Accepted Necklace

Problem 82 » Accepted Necklace 查看标程 Description I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won't accept a necklace which is too heavy. Given the

江湖小小生 696

【MediaPipe实战】从零构建实时人脸关键点检测与表情分析系统

本文详细介绍了如何使用MediaPipe框架从零构建实时人脸关键点检测与表情分析系统。通过Python代码实现,系统能够精准检测468个3D人脸关键点,并实时分析用户表情,适用于智能交互应用。文章包含环境配置、核心实现、可视化技巧及性能优化等实战内容,帮助开发者快速掌握深度学习在计算机视觉中的应用。

weixin_30836759的博客 78

Ragflow技术栈分析及二次开发指南

Ragflow是目前团队化部署大模型+RAG的优质方案,不过其仍不适合直接部署使用,本文将从实际使用的角度,对其进行二次开发

兴趣使然的创作者 1万+

HDU2660 Accepted Necklace

Accepted Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2235    Accepted Submission(s): 868 Problem Description I have N prec

花花的笔记 1038

【医学影像】Deep Learning for Automatic Pneumonia Detection

写在前面的话: 这篇论文是北美放射学会(RSNA)在Kaggle平台上托管的肺炎区域检测挑战赛取得第二名成绩的解决方案。因为笔者需要用到其中的图像增强方案,因此本篇博客只介绍了数据集和图像增强,关于模型的改进和其它改进点没有涉及。 论文地址:https://arxiv.org/abs/2005.13899 代码地址:https://github.com/tatigabru/kaggle-rsna 比赛地址:https://www.kaggle.com/c/rsna-pneumonia-detection-c

chenzhoujian_的博客 1575

Accepted Necklace HDU - 2660

Accepted Necklace HDU - 2660 WA wa了两发又双叒叕是因为没读清楚题我裂开 AC代码 好家伙一手最low的dp竟然过了,我还一直不敢交hhhh #include <bits/stdc++.h> using namespace std; int const N = 2000; int dp[30][N][30]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #en

Zoybzo想AK 148

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

HDU-2660 Accepted Necklace

专题I D-DFS 题面 I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won’t accept a necklace which is too heavy. Given the value and the weight of each precious s...

h_bby的博客 224

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Accepted Necklace hdu 2660

Accepted Necklace Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1022Accepted Submission(s): 406 Problem Description I have N precious...

weixin_30314793的博客 152

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU 2660 Accepted Necklace

http://acm.hdu.edu.cn/showproblem.php?pid=2660 做下这道二维费用的问题。。。。。 结果自己把两个维数代表的东西都搞反了,最重要的是TM的样例过了。。。 然后自己就泪奔。。。。 最后看别人题解,和自己是一样的啊。。。 然后就仔细看了下代码,过了。 内循环其实是可以互换循环的位置的。 不知道为什么AC 1 #include ...

dicuanjiang7084的博客 102

hdu-2660 Accepted Necklace

http://acm.hdu.edu.cn/showproblem.php?pid=2660 题意:给出宝石的数目n,制成项链所需的宝石个数k,然后再给出每个宝石的价值与重量,还有母亲会接受的最大重量,求出在小于等于最大重量范围内,项链的价值尽可能大。 思路:首先n比较小,可以用搜索解决,但是需要剪枝,不然会超时,剪枝就是每次保存上一次搜索到的地方,避免重复。当然  这还是一个二位费用的背包问

有一种力量叫乐观 619

HDU2660 Accepted Necklace 题解

原题 http://acm.hdu.edu.cn/showproblem.php?pid=2660 题目大意 一串项链,每颗石头都有价值和质量,用k颗石头做成一个最贵的项链,输出它的价值 题目分析 典型0/1背包,这里用最容易写的dfs写法 咳咳,既然这是搜索专题,数据又这么小,那就给点面子写个dfs吧【虽然0/1背包也不难 原题 #include<cstdio> #include&...

juseice的博客 177

Accepted Necklace/HDU 2660/DFS

Accepted Necklace/HDU 2660/DFS 题目 I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won’t accept a necklace which is too heavy. Given the value and the weig...

weixin_45600829的博客 300

Hdu2660 Accepted Necklace【简单dfs】

http://acm.hdu.edu.cn/showproblem.php?pid=2660 题目大意:n个珠子里面找k个珠子,使得价值最大但重量不超过某一限定值。 直接对要不要第i颗珠子进行dfs,搜索过程中注意剪枝。 #include <cstdio> #include <cstring> #include <iostream&g...

bantengbang8949的博客 182

HDU 2660 Accepted Necklace

Description I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won't accept a necklace which is too heavy. Given the value and the weight of each precious

愿岁并谢,与长友兮 482

hdu 2660 Accepted Necklace DFS

I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won't accept a necklace which is too heavy. Given the value and the weight of each precious stone, please

小周周i的博客 396

HDU2660 Accepted Necklace【0-1背包】

Accepted Necklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5018 Accepted Submission(s): 1979 Problem Description I have N precious st...

海岛Blog 542
上一篇: poj 3253 Fence Repair
下一篇: hdu 1427 速算24点
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址