2015CCPC南阳场 D - Pick The Sticks

VSCode + Clangd 配置避坑实录:从‘红波浪线’到完美代码提示的完整心路 本文详细记录了VSCode与Clangd配置过程中的常见问题及解决方案,从编译数据库生成到参数调优,帮助C++开发者快速解决代码提示失效、头文件找不到等问题,实现完美代码补全体验。重点介绍了Clangd与LLDB的集成配置及性能优化技巧,适用于Linux和跨平台开发环境。 阅读详情


D - Pick The Sticks
Time Limit:10000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u

Description

The story happened long long ago. One day, Cao Cao made a special order called "Chicken Rib" to his army. No one got his point and all became very panic. However, Cao Cao himself felt very proud of his interesting idea and enjoyed it. 

Xiu Yang, one of the cleverest counselors of Cao Cao, understood the command Rather than keep it to himself, he told the point to the whole army. Cao Cao got very angry at his cleverness and would like to punish Xiu Yang. But how can you punish someone because he's clever? By looking at the chicken rib, he finally got a new idea to punish Xiu Yang. 

He told Xiu Yang that as his reward of encrypting the special order, he could take as many gold sticks as possible from his desk. But he could only use one stick as the container. 

Formally, we can treat the container stick as an   length segment. And the gold sticks as segments too. There were many gold sticks with different length   and value  . Xiu Yang needed to put these gold segments onto the container segment. No gold segment was allowed to be overlapped. Luckily, Xiu Yang came up with a good idea. On the two sides of the container, he could make part of the gold sticks outside the container as long as the center of the gravity of each gold stick was still within the container. This could help him get more valuable gold sticks. 

As a result, Xiu Yang took too many gold sticks which made Cao Cao much more angry. Cao Cao killed Xiu Yang before he made himself home. So no one knows how many gold sticks Xiu Yang made it in the container. 

Can you help solve the mystery by finding out what's the maximum value of the gold sticks Xiu Yang could have taken?
 

Input

The first line of the input gives the number of test cases,  .   test cases follow. Each test case start with two integers,   and  , represents the number of gold sticks and the length of the container stick.   lines follow. Each line consist of two integers,   and  , represents the length and the value of the  gold stick.
 

Output

For each test case, output one line containing  Case #x: y, where   is the test case number (starting from 1) and   is the maximum value of the gold sticks Xiu Yang could have taken.
 

Sample Input

      
4 3 7 4 1 2 1 8 1 3 7 4 2 2 1 8 4 3 5 4 1 2 2 8 9 1 1 10 3
 

Sample Output

      
Case #1: 2 Case #2: 6 Case #3: 11 Case #4: 3

Hint

 In the third case, assume the container is lay on x-axis from 0 to 5. Xiu Yang could put the second gold stick center at 0 and put the third gold stick center at 5, so none of them will drop and he can get total 2+9=11 value. In the fourth case, Xiu Yang could just put the only gold stick center on any position of [0,1], and he can get the value of 3. 
题意:给你一个容器的体积,再给n个物品,往容器里面放东西,只要物品的重心在容器里面就可以了,所以物品的总体积有可能大于容器的体积,这是这道题的难点,否则就是普通的背包了。我们可以这样想,再开多一维数组来记录边缘没有完全放进容器里的物品个数,因为只有两端,所以最多也就两个物品分别在两端没有完全在容器里面。那么这个问题就化简为简单的三维背包问题了。还有两个问题就是,容器里面能只放一个任意大的物品,因为只要把物品放在中间,怎么都是平衡的,所以要考虑只放一个的情况。

还有另外一个问题就是,只把重心放在容器里面把体积的一半放进去,这是会出现小数的,所以我们应该把全部体积乘上2再计算。下面给代码。

#include<iostream>
#include<stack>
#include<cstring>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
int main(){
	int t;
	scanf("%d", &t);
	for (int tcase = 1; tcase <= t;tcase++){
		int n, l;
		scanf("%d%d", &n, &l);
		int a[1005], b[1005];
		LL dp[4010][2][3];
		LL maxnum = 0;
		for (int i = 0; i < n; i++){
			scanf("%d%d", &a[i], &b[i]);
			a[i] =a[i]<<1;
			maxnum = max((LL)b[i], maxnum);
		}
		memset(dp, 0, sizeof(dp));
		int now = 1;
		for (int i = 0; i < n; i++){
			now = now ^ 1;
			for (int j = 1; j <= l<<1; j++){
				for (int k = 0; k < 3; k++){
					dp[j][now][k] = dp[j][now ^ 1][k];
					if (j - a[i] >= 0){
						dp[j][now][k] = max(dp[j][now][k], dp[j - a[i]][now ^ 1][k]+b[i]);
					}
					if (k&&(j - (a[i]>>1))  >= 0){
						dp[j][now][k] = max(dp[j][now][k], dp[j - (a[i] >>1)][now ^ 1][k-1]+b[i]);
					}
				}
			}
		}
		maxnum = max(maxnum, dp[l<<1][now][0]);
		maxnum = max(maxnum, dp[l<<1][now][1]);
		maxnum = max(maxnum, dp[l<<1][now][2]);
		printf("Case #%d: %lld\n",tcase, maxnum);
	}
}




思路二:

用dp[i][M][k] 表示用前i种物品放在长度为M的大木块上,两端放了k个小木棒的做法。

所以dp[i][j][k]=max   dp[i-1][j-a[i].length][k] + a[i].value

       dp[i][j][k]=max   dp[i-1][j-a[i].length/2][k-1] + a[i].value

但是这样写会爆内存,那就降维吧。方法跟二维01背包降维一样

代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1005;
typedef long long LL;
LL dp[4*maxn][4],maxvalue;
int T,N,M;
struct node
{
	LL value,length;
}a[maxn];
void init() 
{
	memset(dp,0,sizeof(dp));
}
void input()//输入 
{
	scanf("%d%d",&N,&M);
	maxvalue=0;
	M*=2;
	for(int i=1;i<=N;i++)
	{
		scanf("%lld%lld",&a[i].length,&a[i].value);
		a[i].length=a[i].length*2;
		maxvalue=max(maxvalue,a[i].value);
	}
}
int main()
{
	scanf("%d",&T);
	for(int tcase=1;tcase<=T;tcase++)
	{
		init();
		input();
		for(int i=1;i<=N;i++)//dp[i][j]  把前i件物品放入容量为j的背包的最大收益
		{
			for(int j=M;j>=a[i].length/2;j--)
			{
				for(int k=0;k<3;k++) 
				{
					if(j-a[i].length>=0)dp[j][k]=max(dp[j][k],dp[j-a[i].length][k]+a[i].value);
					if(k>0)
					{
						if(j-a[i].length/2>=0)dp[j][k]=max(dp[j][k],dp[j-a[i].length/2][k-1]+a[i].value);
					}
				}
			}
		}
		printf("Case #%d: ",tcase);
		LL ans=max(max(dp[M][0],dp[M][1]),max(dp[M][2],maxvalue));
		cout<<ans<<endl;
	}
}


华为 MetaERP 通过元数据驱动的多组织架构 + 内部交易协同 + 自动对账引擎 + 合并规则引擎,实现多组织内部往来与合并报表的全流程自动抵消,核心是源头标准化、过程自动化、结果可追溯 摘要: 华为MetaERP通过元数据驱动的多组织架构与主数据标准化,实现内部往来与合并报表全流程自动化。其核心包括:统一组织模型与主数据(确保数据口径一致)、内部交易协同(自动生成对称凭证)、智能对账引擎(多维度自动匹配差异)、合并规则引擎(配置化抵消模板)。依托GaussDB高性能数据库与流批一体架构,华为全球88家子公司合并报表效率提升400%,关账时间缩短至2小时,支持多准则、多币种自动抵消,审计全程可追溯。相比传统ERP,MetaERP在协同性、自动化与扩展性上优势显著,为跨国集团提供高效、准确的合 阅读详情

相关推荐

Innovus快捷键大全:从入门到精通的效率提升指南

本文是Innovus快捷键从入门到精通的效率提升指南,旨在帮助芯片后端设计工程师通过掌握核心快捷键,将重复性鼠标操作转化为高效的肌肉记忆,从而显著提升版图设计、编辑和分析的工作流速度。文章系统讲解了视图导航、对象选择编辑、流程管理等关键快捷键组合,并提供了个性化配置与实战策略,助力工程师突破效率瓶颈,实现人机合一的流畅设计体验。

silver的专栏 797

D - Pick The Sticks 【01背包扩展】【扩容版】

状态计算:根据两侧露出情况进行状态转移。分两种,加入这一种导致露出数增加和加入露出数不增加。前一种由k-1进行转移,后一种就是当前的第k层。状态表示f[j][k] : j表示当前背包容量,k表示两侧是否有露出的情况 显然是01背包1维优化后再用另一维表示两侧状态。直接看代码 注意若物品太大,即一半也比总容量大,这种情况只能放一种改物品,只需要比较一下最大价值取最大就ok了。...

Monster_six的成长记录之路 276

这可是全网网工数通方向学习路线最完整,最详细的版本,没有之一

文章篇幅较长,耐心看完你一定有所收获。

最铁头的网工博客 2万+

2015南阳CCPC D - Pick The Sticks dp

参考:http://www.cnblogs.com/qscqesze/p/4899344.htmlD - Pick The SticksTime Limit: 1 Sec Memory Limit: 256 MB 题目连接无 DescriptionThe story happened long long ago. One day, Cao Cao made a special order ca

now_ing的博客 265

计算机网络之NAT的解释与实验配置

NAT 静态NAT 动态NAT easy_ip NAT服务器映射

爱学习的JackYang的博客 1918

Robosuite实战:通过Xbox手柄实现机械臂6-DoF精准控制的完整指南

本文详细介绍了如何通过Xbox手柄实现机械臂的6-DoF精准控制,结合Robosuite仿真环境与MuJoCo物理引擎,提供从环境配置到代码实现的完整指南。文章重点解析了手柄映射原理、核心控制代码以及数据采集优化技巧,帮助开发者高效完成机械臂控制任务。

weixin_29169505的博客 419

南阳ccpc D题 Pick The Sticks

Pick The Sticks Time Limit: 15000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  Status The story happened long long ago. One day, Cao Cao made a special

dml_96的博客 864

unity游戏开发日志(一)将mmd模型导入unity,并解决材质丢失的问题

unity音乐游戏开发,导入角色模型并解决材质问题

yizhigou1的博客 1762

Pick The Sticks【背包 CCPC D题】

这题同样赛场上过了白人,不同的是这题我们有一点点思路,不过由于对背包问题一知半解,我们并没有找到正确的解法。 题意:给一个长度为L的平台,和n根金条的长度与价值,金条只能在平台上摆一长条,且每根金条的重心不能超出平台边缘。 这题的变化就在于金条并不是完全必须放在平台上,如果是完全必须放在平台上,则题目就是一个标准的01背包问题了,但是由于首尾两端可以放出去一半的长度,就是说有两

Ivan_wb的博客 747

PCIe学习笔记(一)-------1.3 PCIe数据包(TLP,DLLP,PLP)

1,PCIe的层次结构 PICe设备在硬件电路上可以分为三个层次结构:事务层(Transaction Layer)、数据链路层(Data Link Layer)、物理层(Physical)。每一个层次又可以分为两个部分,分别为处理发送和处理接收的部分。 也可以分为四个层次,将事务层以上的层次称为软件层(Software Layer)。 2,PCIe数据包 前面已经说过PCIe之间是以数据包的形式来传输数据的,协议共定义了3类数据包。与处理层相关的是处理层数据包(TLP),与数据链路层相关的是数据

llxxyy507的博客 2万+

搭建问答系统

数据描述 import docx import jieba from gensim.models import Word2Vec import os import numpy as np import pickle as pk import warnings from copy import deepcopy warnings.filterwarnings("ignore") from mu...

微信号:RunsenLiu 1840

2015 南阳CCPC hdu5543 Pick The Sticks(01背包)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5543 题目大意: 在一个狭长的容器里面放一些长木棍,每根木棍的长度和价值都不同,现在通过放置木棍使得能够得到的总价值最大。木棍放置不能重叠,对于任意一根木棍,只要他的重心落在容器里面,就算有一部分出去了,也算能够放下。 题目范围:N 思路: 对于这样一个问题,如果范围小的话,我们大可

hahahaha 1034

LeRobot 入门教程(十四)Meta-World 机器人多任务与元强化学习操作仿真基准平台

Meta-World是一个开源机器人操作模拟基准平台,专注于多任务与元强化学习研究。该平台提供50项多样化任务(MT50套件),采用标准化评估协议测试算法泛化能力。LeRobot平台支持Meta-World任务评估,提供预处理数据集和训练工具。用户可通过命令行快速训练SmolVLA策略,并评估模型在简单、中等、困难等不同难度任务上的表现。文章还提供了兼容性问题和实用技巧建议,如使用完整MT50任务集测试泛化能力、采用one-hot任务条件化等。这些资源为研究人员开展机器人多任务学习提供了标准化实验环境。

2506_90492529的博客 1021

【HDU5543 2015 CCPC 南阳国赛D】【贪心+DP】Pick The Sticks 木棍重心放在容器内 贪心法+三维状态直接法

这题我采取了两种做法。下面提供两份代码。 前者较为麻烦,但是基于一定的贪心原则, 状态少,效率高。后者写起来方便,速度稍慢。 #include #include #include using namespace std; #define MS(x,y) memset(x,y,sizeof(x)) #define MC(x,y) memcpy(x,y,sizeof(x)) typedef

snowy_smile的博客 2066

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

2015南阳CCPC D - Pick The Sticks 背包DP.

D - Pick The Sticks Description The story happened long long ago. One day, Cao Cao made a special order called "Chicken Rib" to his army. No one got his point and all became very panic. However, C...

weixin_30455661的博客 118

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

2015CCPC南阳场 H - Sudoku

比赛的时候都错了题意我去。。一直TLE+WA.. 赛后看了题解才知道都错了题意。。愧疚啊我去。。这次比赛我读的两道题都读错了题意,坑死队友。。 H - Sudoku Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU

overload1997 676

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

2015ccpc南阳个人题解

Secrete Master Plan 签到题,枚举4种情况判断相同即可。 #include<cstdio> #include<cstring> using namespace std; int a[4][2]; void turn() { int te = a[0][0]; a[0][0] = a[1][0], a[1][0] = a...

weixin_40191952的博客 346

2015南阳CCPC部分题目代码

我是部分按照难度来排序的,越简单的越前面。 首先是L题。 #include #include using namespace std; int main() { int t;scanf("%d",&t); for(int s = 1;s <= t;s ++) { int n; scanf("%d",&n); printf("Cas

sabervsarcher的博客 1046

2015 ccpc 南阳国赛

A 2*2矩阵 问可不可以通过旋转 得到另外个 直接模拟 #include<stdio.h> #include<algorithm> #include<string.h> #include<string> #include<stdlib.h> #include<set> #include<ite...

weixin_30682127的博客 264

2015 CCPC D- Pick The Sticks(UESTC 1218) (01背包变形)

http://acm.uestc.edu.cn/#/problem/show/1218 既然二维dp表示不了,就加一维表示是否在边界放置,放置一个,两个。有一个trick就是如果只放一根,那么多长都可以。 wa了好多次(囧) 开始因为l[i]/2会出现小数,没注意,把所有的长度都x2就可以解决。 又wa了n次因为没注意j-l[i]时没加判断,为什么不是RE呢!不开心。。。 /****...

weixin_30580943的博客 168

D - Pick The Sticks HDU - 5543(特殊的01背包,dp,放金条超出背包空间)

D - Pick The Sticks HDU - 5543 The story happened long long ago. One day, Cao Cao made a special order called “Chicken Rib” to his army. No one got his point and all became very panic. However, Cao Cao himself felt very proud of his interesting idea and en

Are_you_ready的博客 343

2016多校联赛6H (hdu5800) To My Girlfriend

To My Girlfriend Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 346    Accepted Submission(s): 126 Problem Description Dear Guo

overload1997 1323

hdu 6086 Rikka with String ac自动机+dp

Rikka with String Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 210    Accepted Submission(s): 58 Problem Description As we know,

overload1997 1218

2015CCPC南阳场 C - The Battle of Chibi

C - The Battle of Chibi Time Limit:4000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5542 Description Cao Cao made up a big army and was go

overload1997 969

2016ccpc 合肥站hdu 5965 扫雷

扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 38    Accepted Submission(s): 10 Problem Description 扫雷游戏是晨晨和小璐特别喜欢的智力游戏,她俩最近沉迷其

overload1997 917
上一篇: 2015CCPC南阳场 H - Sudoku
下一篇: 2016多校联赛3C (hdu5754) Life Winner Bo
overload1997
博客等级 码龄11年 328粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值