CodeForces - 365D D. Free Market

基于STM32设计的老人防摔倒报警设备(OneNet)_65 本文设计了一种基于STM32单片机的智能老人防摔倒报警设备。该系统结合MPU6050陀螺仪传感器实时监测老人的姿态变化,检测摔倒事件;通过SIM800C通信模块发送短信通知紧急联系人,并将GPS定位信息上传至云端平台,确保家属能够及时了解老人的准确位置。 阅读详情
D. Free Market
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

John Doe has recently found a "Free Market" in his city — that is the place where you can exchange some of your possessions for other things for free.

John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that each item is one of a kind and that means that you cannot exchange set {a, b} for set {v, a}. However, you can always exchange set x for any set y, unless there is item p, such that p occurs in x and p occurs in y.

For each item, John knows its value ci. John's sense of justice doesn't let him exchange a set of items x for a set of items y, if s(x) + d < s(y) (s(x) is the total price of items in the set x).

During one day John can exchange only one set of items for something else. Initially, he has no items. John wants to get a set of items with the maximum total price. Find the cost of such set and the minimum number of days John can get it in.

Input

The first line contains two space-separated integers n, d (1 ≤ n ≤ 50, 1 ≤ d ≤ 104) — the number of items on the market and John's sense of justice value, correspondingly. The second line contains n space-separated integers ci (1 ≤ ci ≤ 104).

Output

Print two space-separated integers: the maximum possible price in the set of items John can get and the minimum number of days needed to get such set.

Examples
input
3 2
1 3 10
output
4 3
input
3 5
1 2 3
output
6 2
input
10 10000
10000 9999 1 10000 10000 10000 1 2 3 4
output
50010 6
Note

In the first sample John can act like this:

  • Take the first item (1 - 0 ≤ 2).
  • Exchange the first item for the second one (3 - 1 ≤ 2).
  • Take the first item (1 - 0 ≤ 2).

先把所有可能交换出来的状态递推出来,然后贪心找一遍

重要的是不要考虑交换那个物品,要整体考虑,我当前这个状态(a)可以通过换某些东西,换到【a+1,a+d】中的某个状态

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define eps 1e-9
#define PI 3.141592653589793
#define bs 1000000007
#define bsize 256
#define MEM(a) memset(a,0,sizeof(a))
#define inf 0x3f3f3f3f
#define rep(i,be,n) for(i=be;i<n;i++)
typedef long long ll;
using namespace std;
int dp[550005];
int main()
{
	int n,d,c,i,j,x,flog;
	scanf("%d %d",&n,&d);
	dp[0]=1;//1表示i这个状态出现过,0表示没出现
	for(i=0;i<n;i++)
	{
		scanf("%d",&c);
		for(j=500000;j>=c;j--)
		{
			dp[j]|=dp[j-c];
		}
	}
	int day=0;
	x=0;
	
	while(1)
	{
		flog=0;
		for(j=x+d;j>x;j--)
		{
			if(dp[j])
			{
				flog=1;
				day++;
				x=j;
				break;
			}
		}
		if(!flog)
		break;
	}
	printf("%d %d\n",x,day);
 }




uniapp [微信小程序] - 详解微信小程序端接入mqtt全流程及示例源码教程,uniApp微信小程序端如何接入MQTT插件并实现连接/断开+发布订阅+消息队列+离线重连等各种示例代码(开箱即用) uniapp微信小程序接入MQTT,uniapp中使用mqtt,uniapp 微信小程序端接入mqtt示例代码教程,适用于微信小程序的MQTT插件,uniapp开发微信小程序连接mqtt,uniApp微信小程序接入MQTT协议,uniapp vue3微信小程序使用MQTT的小例子接入流程,使用uniapp开发小程序接入mqtt,如何在uniapp项目中使用mqtt,uniapp mqtt的使用示例,mqtt连接报错,如何在项目里集成mqtt,Mqtt协议,主动连接mqtt,订阅消息,实现发布,订阅和接收消息 阅读详情

相关推荐

Mac上VMware Fusion手动安装VMware Tools实现跨系统复制粘贴

本文详细指导了在Mac的VMware Fusion中手动安装VMware Tools的完整流程,以解决虚拟机与宿主机之间无法复制粘贴的常见问题。通过定位安装镜像、挂载、解压并运行安装脚本,最终实现跨系统无缝数据交换,提升工作效率。

orange的博客 698

D - Free Market CodeForces - 365D 背包求状态数+贪心 好题!

John Doe has recently found a "Free Market" in his city — that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (e

Marcus-Bao的个人主页 963

KUKA .RSI 软件包

KUKA RSI软件包通过XML文件使得机器人与外部设备(传感器通讯)通讯成为了可能,但仍存在诸多限制,该模块最多允许9台设备进行连接,有限的IO口,匮乏的功能,并且需要投入大量精力琢磨相关说明文档。为此开发人员针对KUKA实时通讯,做了一些开源的接口使得上位机与机械臂的通讯更为简单。

huhu7777的博客 3293

CodeForces 364 B. Free Market

B. Free Market time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output John Doe has recently found a "...

369540808 188

解锁RK1126与SC132GS摄像头适配密码:技术与代码全解析

本文详细介绍了瑞芯微RK1126芯片与SC132GS摄像头的适配方法。首先分析了RK1126的四核Cortex-A7处理器、Mali-T860 GPU等硬件特性,以及SC132GS的130万像素、全局快门等技术参数。重点阐述了基于MIPI CSI接口的硬件连接原理和基于V4L2框架的软件驱动设计,并提供了完整的初始化、数据采集和图像处理代码实现。针对常见连接和图像质量问题给出了解决方案,展现了该组合在智能安防、工业检测等领域的应用潜力,为开发者提供了实用的技术参考。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 1502

基于MATLAB的逐次变分模态分解(SVMD)算法详解

本文详细介绍了基于MATLAB的逐次变分模态分解(SVMD)算法。SVMD是一种改进的变分模态分解方法,通过逐次分解机制克服传统VMD算法需要预设模态数量的缺陷。文章从信号分解方法的发展历程入手,阐述了SVMD的核心优势与创新点,包括参数敏感性降低、自适应分解能力和更好的频率分离性能。详细解析了SVMD的数学模型和优化求解过程,重点讨论了变分问题构建、ADMM优化方法和停止准则设计。通过MATLAB代码实现展示了SVMD的具体应用,包括参数初始化、信号预处理、模态提取和残余信号更新等关键步骤。

qq_42212808的博客 130

Codeforces 365D 贪心+dp

D. Free Markettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe ...

qq_36876305的博客 344

Windows 11 安装 JDK 25:下载、安装、配置环境变量、验证

本文详细介绍了在 Windows 11 系统上安装 JDK 25 的完整流程,包括从 Oracle 官网下载压缩包、解压至自定义目录、配置 JAVA_HOME 与 Path 环境变量,并验证安装是否成功。文章推荐使用 ZIP 压缩包而非 EXE 安装程序,以实现绿色便携、多版本共存和灵活管理。最后通过一个使用 Java 25 新特性的示例程序,验证 JDK 的编译与运行环境。

寒水馨 · 轻量级技术文档 · hanshuixin.org 7661

CodeForces - 365D Free Market 背包求状态数+贪心

传送门:CodeForces - 365D 题意:有n种物品,每种物品有它的价值,john要和别人做交易,每次交易双方物品集合的总价值之差不能超过d,每天john只能做一笔交易,一开始john什么都没有,另一个人有所有的n种物品,问john最多能获得多大价值的物品,最少用多少天能获得最大价值的物品。 思路:我刚开始做这个题就是xjb模拟加贪心,最大价值还好说,天数一直搞不定,看了题解才发现要用

WA是一笔财富 503

第01章 Hermes Agent 是什么

如果读者所在的开发团队已经引入了 Cursor、Claude Code 这类 AI IDE,可能会有一个困惑:写代码已经有 AI 帮忙了,还需要 Hermes Agent 做什么?这一章将给出答案。Hermes Agent 不是另一个写代码的 AI,而是一个常驻在团队里的"AI 协作成员",专门负责写代码之外的协作环节——讨论需求、审查代码、查日志、监控告警、生成报告。学完本章,读者将清楚 Hermes 的定位以及它在团队里的角色。

亢少军的博客 75

WorkBuddy 技能指南:基础办公与文档处理

WorkBuddy 不仅仅是一个对话工具——它通过技能(Skills)系统,将通用 AI 助手转变为具备专业领域能力的智能助手。每个技能都是一套经过精心设计的"能力包",包含专业知识、工作流程和专用工具。本文聚焦于文档处理类技能——这是日常工作中使用频率最高、最实用的能力集合。

u011186532的专栏 703

CodeForces-787B(题目不好读懂,懂了题目就发现是水题,感觉自己棒棒哒)

CodeForces-787B(题目不好读懂,懂了题目就发现是水题,感觉自己棒棒哒) 题目链接 题目大意:我做这个题的时候读了半个小时题才明白要干什么,哎。题意就是给出n个宇宙,m个小组,下面的m行每行第一个给出该小组成员的人数num,然后接着给出每个成员来自哪个星球,互为相反数的来自一个星球,其中必有一个是好人一个坏人,如果有一个小组可能全是坏人(也就是说如果有一个小组里没有相反数)那么就输出YE

V32122的博客 1007

Cadence OrCAD Capture 软件自带元件原理图符号库目录与介绍图文视频教程

硬件工程师在开始原理图设计时,应该首先拥有自己的元件原理图符号库。基于Capture进行原理图设计的一个很大的优点就是,软件自带的元件库比较全。本文简单介绍Capture软件自带元件库。

fydar的博客 5579

[背包 贪心] Codeforces #365D. Free Market

思维题。 首先要挖掘一下性质,这个交换的操作限制很大,较难处理。 可以发现,我们进行一次交换,价值总和增长不会超过 dd 。 若我们要从 SS 变到 TT,需用 S−S∩TS-S \cap T 交换得 T−S∩TT-S \cap T ,需满足 Sum(S−S∩T)+d≥Sum(T−S∩T)→Sum(S)+d≥Sum(T)Sum(S-S \cap T)+d \ge Sum(T-S \cap T

Lynstery's blog 545

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

NTscan扫描工具

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

Codeforces Round #213 (Div. 2)-D. Free Market

地址:http://codeforces.com/problemset/problem/365/D 思路:贪心,思想十分巧妙(只可意会不可言传QAQ),先将所有能够到达的状态先做标记,在从sum=0开始每次取 (sum,sum+d]的最大状态,同时记录搜索次数s,这样到搜索不到时,sum,s即为答案。 Code : #include&lt;iostream&gt; #include&l...

随风而行的博客 350

Statistics and Machine Learning Toolbox

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

B - Free Market 涉及背包问题 + DP

B -Free Market Time Limit:1000MSMemory Limit:262144KB64bit IO Format:%I64d & %I64u SubmitStatus Appoint description: System Crawler (2013-11-23) Description Joh...

weixin_30593261的博客 137

Round #5 Problem B

Problem Description John Doe has recently found a "Free Market" in his city that is the place where you can exchange some of your possessions for other things for free. John knows that his city

野生的声威的专栏 647

B. Free Market----暴力+dp

B. Free Market time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output John Doe has recently found a "Free Market" i

bless295的博客 390

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

jerans的博客 1085

URAL - 2072 Kirill the Gardener 3 dp

2072. Kirill the Gardener 3 Time limit: 2.0 second Memory limit: 64 MB Kirill the gardener has got a new task. He has to water the flowers growing on the huge flowerbed! It should be mentio

jerans的博客 960

CodeForces - 361D Levko and Array二分加dp

D. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Levko has an array that consists of inte

jerans的博客 840

Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率dp

D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Bad Luck Island is inhabited by thre

jerans的博客 648

Codeforces Round #426 (Div. 2) C. The Meaningless Game 思维 D. The Bakery dp

题目:http://codeforces.com/contest/834/problem/C 题意:两个人玩游戏, 两个人初始值都为1,每次可以选一个正整数,一个人乘以这个正整数的平方,一个人乘以这个正整数,给你多对数,判断会不会出现这个游戏局面 把ab乘起来,判断是不是一个数的三次方,并且是不是能被a和b整除 k^3==a*b&&a%k==0&&b%k==0 结果找k的二分写错了。。。。

jerans的博客 648

Codeforces Round #433(Div. 1,based on Olympiad of Metropolises)A Planning B Jury Meeting C Boredom

人生的第一次div.1 掉分 QAQ A - Planning http://codeforces.com/contest/853/problem/A 贪心,排个序,优先安排花费大的,用模拟链表实现的 #include #define eps 1e-9 #define PI 3.141592653589793 #define bs 1000000007 #define bsize

jerans的博客 626

qduoj kkun和CerberuX

kkun和CerberuX 发布时间: 2017年1月1日 15:11   最后更新: 2017年1月1日 15:16   时间限制: 2000ms   内存限制: 128M 描述 这一天kkun和CerberuX日常在玩游戏,这时候,他们发现了一个双人合作类游戏。 给出一个n*m的地图,地图的每个格子都有分数,由kkun从左上角跑到右下角,CerberuX从左下角跑到

jerans的博客 624

Codeforces Round #396 (Div. 2)C. Mahmoud and a Message

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of lengt

jerans的博客 576

Codeforces Round #417 (Div. 2)Sagheer, the Hausmeister 乱搞 Sagheer and Nubian Market 二分

B. Sagheer, the Hausmeister time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Some people leave the lights at

jerans的博客 565
上一篇: UVA - 674 Coin Change 多重背包or母函数
下一篇: Tyvj p1336 火车进站 搜索//全排列
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值