POJ3624 Charm Bracelet 01背包裸题

Charm Bracelet poj 3624 (01) 背包问题 c++ Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23076   Accepted: 10383 Description Bessie has gone to the mall's jewelry store and spies a 阅读详情
Description

Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).

Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.

Input

* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di

Output

* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints

Sample Input

4 6
1 4
2 6
3 12
2 7
Sample Output

23
Source

USACO 2007 December Silver


#include <iostream>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
int dp[13000];
int main()
{
    int n,w;
    int wei[3500],pri[3500];
    while(~scanf("%d%d",&n,&w)){
        for(int i=1;i<=n;i++){
            scanf("%d%d",&wei[i],&pri[i]);
        }
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++){
            for(int j=w;j-wei[i]>=0;j--){
                dp[j]=max(dp[j],dp[j-wei[i]]+pri[i]);
            }
        }
        printf("%d\n",dp[w]);
    }
    return 0;
}



量产导入 | 产品可靠性测试标准完整大集合(JEDEC/IEC/SAE…) 产品可靠性测试是产品质量保证中的重要一环, 包含有Pre-con, aging(寿命)和ESD(静电)等, 下面就收集了权威标准JEDEC全系列, 请参照如下 同时也附上其它的可靠性标准供大家参考及交叉理解, 可能侧重点不同, 大家可以参考下。 阅读详情

相关推荐

保姆级教程:用SSH手动重建黑群晖RAID1阵列,修复‘存储空间损毁’

本文提供了一份详细的SSH手动重建黑群晖RAID1阵列的教程,帮助用户修复‘存储空间损毁’问题。通过深入解析mdadm软RAID的底层逻辑,从诊断到重建的全过程,确保用户能够掌握黑群晖存储池的修复技术。适用于技术爱好者和系统管理员。

weixin_30319153的博客 292

POJ 3624

这是个典型的01背包问题,很基础的,我就做了。 题目大意: 在N个花费为Ci、价值为Wi的物品中(i=1...N),选取若干个,使得所有物品的总花费不大于M,而其总价值最大。 ----------------------------------------------------------------我是华丽的分割线-----------------------------------

hello_cosmos的专栏 2322

【机器学习】实验2,基于回归分析的大学综合得分预测(完整代码实现+分析)

大学排名是一个非常重要同时也极富挑战性与争议性的问题,一所大学的综合实力涉及科研、师资、学生等方方面面。目前全球有上百家评估机构会评估大学的综合得分进行排序,而这些机构的打分也往往并不一致。在这些评分机构中,世界大学排名中心(Center for World University Rankings,缩写CWUR)以评估教育质量、校友就业、研究成果和引用,而非依赖于调查和大学所提交的数据著称,是非常有影响力的一个。

高丽大学人工智能硕士在读|专注大模型、RAG、OCR与AI工程实践 1974

poj 3624 Charm Bracelet

题目来源:POJ 3624            简要题目分析: 01背包问题,需要注意的是该题对内存限制比较苛刻,如果用二维数组存储状态内存很有可能爆掉,所以用一维滚动数组。 以二维状态转移方程为例: w[i]代表第i件物品的重量,v[i]代表第i件物品的价值,dp[i,j]代表把前i件物品放入容量为j的背包内所能获取的最大价值,对于第i件物品有两种选择--放或者不放。 伪代码

Polanwind 339

XS5018A TX ISP芯片同轴高清模拟输出图像处理芯片用户指南

当看门狗开启且系统异常,看门狗模块得不到喂狗信号时,自动产生看门狗复位信号,复位​​​​​​​。分量上与人眼对光谱的响应通常是有偏差的,通常通过一个色彩校正矩阵校正光谱响应的交叉效。但实际上由于电路的作用,复位模块对整个芯片及各个功能模块的复位进行统一管理,负责产生各个模块的软复位信。每个区域前景色可以在 16 个色表中查找,单个区域的前景色统一,各个区域的前。较弱的坏点被放大成刺眼的白点和明显的黑点,强烈推荐开启动态坏点校正功能。四种制式,通过寄存器配置,可以很方便的实现四种制式的切换、且可以对截止。

2403_88922712的博客 1960

华为云物联网系统开发(纯云端)外包方案及项目需求说明书

提供一个详细的需求文档(SRS,Software Requirements Specification),用于指导完全零基础的非专业负责人外包兼职专业技术人员开发一款基于华为云物联网平台、Astro低代码平台和Astro Canvas大屏设计的物联网系统,纯软件实现并支持下载部署。文档涵盖详细的软硬件组成清单(聚焦软件和云服务)、技术文档要求等,确保非专业人员在移交后能够复用、扩展和操作该系统。本文档简洁、全面,适合非技术背景的管理者使用,并基于华为云生态的内部实施部署。

hy行者勇哥的博客 620

poj3624java_01背包问题:POJ3624

背包问题是动态规划中的经典问题,而01背包问题是最基本的背包问题,也是最需要深刻理解的,否则何谈复杂的背包问题。POJ3624是一道纯粹的01背包问题,在此,加入新的要求:输出放入物品的方案。我们的数组基于这样一种假设:totalN表示物品的种类,totalW表示背包的容量w[i]表示第i件物品的重量,d[i]表示第i件物品的价值。F(i,j)表示前i件物品放入容量为j的背包中,背包内物品的最大价...

weixin_33120053的博客 946

机器翻译的评价标准:BLEU、ROUGE等指标说明及代码实现

机器翻译领域常用的自动评价指标主要包括BLEU、ROUGE、METEOR和COMET四大类。BLEU基于n-gram精确率和短句惩罚,ROUGE关注召回率,METEOR结合精确率和召回率并考虑同义词,COMET则利用预训练模型计算语义相似度。这些指标各有特点:BLEU适用于机器翻译,ROUGE对长句友好,METEOR更接近人工评分,COMET无需参考译文。代码实现上,sacrebleu、rouge-score等库提供了便捷的计算方式。新兴趋势包括基于BERT等模型的语义评估和大语言模型评估器,但传统指标仍占

数据知道的博客 9418

POJ 3624 01背包问题

01背包问题是动态规划中很基础也很经典的问题,给大家推荐一个网址(背包 九讲),里面讲的很详细。 [url]http://love-oriented.com/pack/P01.html[/url] 按我的理解,01背包就是一种特定价值的物品放到背包中去,要么放,要么不放。循环中嵌套的循环用逆序,复杂度为O(N*W) POJ3624原题为 [url]http://poj.org/pr...

从此爱上猫 268

Arduino与Proteus仿真实例-LCD2004-I2C(PCF8574)驱动仿真

LCD2004-I2C(PCF8574)驱动仿真 PCF8574/74A 通过两线双向 I2C 总线(串行时钟 (SCL)、串行数据 (SDA))提供通用远程 I/O 扩展。 LCD2004,即2004字符型液晶显示器,是一种点阵模块,用于显示字母、数字、字符等。 它由 5x8 个点阵位置组成; 每个位置可以显示一个字符。 两个字符之间有一个点间距,行之间有一个空格,从而将字符和行分开。 模型 2004 表示它显示 4 行,每行 20 个字符。 在前面的实例中对PCF8574和LCD2004的已经做了详细介

视觉与物联智能 1165

华为OD机试 - 停车场费用统计 - HashSet(Python/JS/C/C++ 双机位C卷 100分)

本专栏收录于《华为OD机试真题(Python/JS/C/C++)》。刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、3个测试用例、为什么这道题采用XX算法、XX算法的适用场景,发现新题目,随时更新。停车场统计当日总收费,包月的车不统计,不包月的车半个小时收一块钱,不满半小时不收费,如果超过半小时,零头不满半小时按半小时算,每天11:30-13:30时间段不收费,如果一辆车停车时间超过8小时后不收费。现提供停车场进出车辆的统计信息,需要你来计

学Java,找哪吒 238

POJ-3624-01背包问题

文章目录 有N件物品和一个容积为M的背包 第i件物品的体积是w[i], 价值是d[i] 求解将哪些物品装入背包可以使价值总量和最大 每种物品只有一件,可以选择放或者不放 (N <= 3500, M <= 13000)

超级氯化钾的博客 329

【通信】多径衰落信道的matlab仿真

1 简介 2 部分代码 clearf_c=1e3; %carrier frequency(no modulation)time_1 = (linspace (0, 10, 1000)); %timesignal_in = sin (2 * pi *f_c* time_1); %sine wave plot (time_1, signal_in, 'b');grid on;

qq_59747472的博客 1383

POJ 3624 Charm Bracelet(01背包,裸题)

题目意思: 有N个物品,分别有不同的重量Wi和价值Di,Bessie只能带走重量不超过M的物品,要是总价值最大,并输出总价值。 本题要点: 1、裸的 01背包题目。 参考代码 :《算法竞赛进阶指南》 276页。 开一维数组 dp 2、状态表示: dp[j] 表示 背包中放入总体积为j的物品的最大价值。 #include <cstdio> #include <cstring> #include <iostream> using namespace std; const in

qq_38232157的博客 193

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

【POJ3624】Charm Bracelet 01背包裸题

01背包luo'ti 复制去Google翻译翻译结果

辗转山河弋流歌 1304

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

POJ 3624 Charm Bracelet(01背包裸题)

Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38909 Accepted: 16862 Description Bessie has gone to the mall's jewelry store and spies a ...

weixin_33705053的博客 83

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

POJ 3624 Charm Bracelet(01背包裸题-空间优化)

题意: ...基础背包问题,大概意思是,承重m的背包,有n个物品,第i个物品重w[i],价值p[i],求背包能装入物品的最大价值 把重量设为数组下标 即c[i],i为物品重量,c[i]为背包重i物品的价值 一个公式:c[j]=max(c[j],c[j-w[i]]+p[i]); 意思是,不加上第i个物品时背包的价值,与重量j减去第i个物品重量后背包的价值加上第i个物品的价值比较 不同的是...

Ordinarv 579

POJ 3624 Charm Bracelet(01背包裸题)

#include #include #include using namespace std; const int maxm=1e6+10; int dp[maxm]; int w[maxm]; int v[maxm]; int main() { int m,n; while(scanf("%d%d",&m,&n)!=EOF) { memset(dp,0,s

小马的博客 396

poj 3624 Charm Bracelet 01背包问题

题目链接:poj 3624             这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放。             用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以             获得的最大价值。则其状态转移方程便是:             F [i, v] = max{F [i − 1, v], F [i − 1,

WeberXie 2169

POJ 3624 Charm Bracelet【01背包入门题】

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34333   Accepted: 15215 Description Bessie has gone to the mall's jewelry store and spies a

AC_Dreameng 2085

poj 3624 Charm Bracelet(01背包入门题)

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10399   Accepted: 4667 Description Bessie has gone to the mall's jewelry store and spies a

志当存高远 2201

POJ3624Charm Bracelet题解

01背包一维数组反向优化。

weixin_42178241的博客 169

POJ 3624 Charm Bracelet【裸01背包和关于贪心解 01 背包问题的思考】

原题链接:http://poj.org/problem?id=3624 我的链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=20437#problem/A欢迎来水 Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total

free斩 1765

POJ3624_Charm Bracelet(背包/01背包)

解题报告 题目传送门 题意: 思路:

_nplus 1294

POJ - 3624 Charm Bracelet(01背包)

题目链接: https://vjudge.net/problem/POJ-3624 题解: 标准的01背包问题,非常经典,没有任何坑,用数组记录每一件物品的重量w[i],价值v[i],背包各个重量的最优解dp[j],从第一个物品到最后一个物品,背包空间初始为M(题目给定的值),放入第i件物品,空间减少w[i],价值增加v[i],不断更新直到背包空间为0。 状态更新公式:dp[j]=max(dp...

Sky丨Star的博客 169
上一篇: POJ1458 Common Subsequence 最长公共子序列
下一篇: POJ1088 滑雪
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值