poj 3624(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 阅读详情
Charm Bracelet
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 31347 Accepted: 13942

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


//裸的01背包

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int w[4000],v[4000];
int dp[12885];
int n,m;
void ZeroOnePack(int w,int v)
{
    for(int i=m;i>=w;i--)
        dp[i]=max(dp[i],dp[i-w]+v);
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
            scanf("%d%d",w+i,v+i);
        for(int i=1;i<=n;i++)
            ZeroOnePack(w[i],v[i]);
        printf("%d\n",dp[m]);
    }

    return 0;
}


OrCAD Capture CIS 17.4 原理图绘制 阅读详情

相关推荐

期末求生指南:手把手教你用浏览器开发者工具绕过百一测评切屏检测

本文详细介绍了如何利用浏览器开发者工具绕过百一测评的切屏检测功能。通过分析JavaScript事件监听机制,定位关键检测代码,并提供实时调试和本地覆盖两种修改方法,帮助学生在遵守规则的前提下更灵活地应对在线考试。文章还包含风险控制和替代方案等实用建议。

weixin_28698059的博客 550

[背包] poj 3624 最基本的背包问题

P01: 01背包问题  题目  有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。  基本思路  这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放。  用子问题定义状态:即f[i][v]表示前i件物品恰放入一个容量为v的背包可以获得的最大价值。则其状态转移方程便

童凌的技术博客 1089

STM32 SAES硬件加密协处理器全模式工程实践指南

AES(高级加密标准)是嵌入式系统中最基础且关键的对称密码算法,其硬件加速实现直接影响安全、性能与功耗平衡。Secure AES Coprocessor(SAES)作为STMicroelectronics在STM32U5等高安全MCU中集成的专用密码协处理器,不仅支持标准ECB/CBC/CTR模式,更原生兼容GCM和CCM等认证加密模式,具备抗侧信道、密钥保护与DMA卸载能力。理解其寄存器状态机(CHMOD/MODE/CPHASE)、NPBLB数据对齐机制及GCM四阶段编程范式,是规避Tag校验失败、IV错

weixin_42311427的博客 76

POJ 3624

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

hello_cosmos的专栏 2322

FPGA网络调试实战:基于88E1111和DP83867两款PHY芯片的SGMII-UDP数据回环对比与避坑指南

本文深入对比了88E1111与DP83867两款PHY芯片在SGMII-UDP数据回环中的性能差异,涵盖硬件设计、Vivado工程配置及调试技巧。通过实测数据揭示DP83867在吞吐量、延迟和功耗方面的优势,并提供FPGA网络调试中的常见问题解决方案,助力工程师高效完成项目开发。

weixin_31682031的博客 384

深入解析DisplayPort(DP)接口:从主链路到辅助通道的全方位技术剖析

本文深入解析DisplayPort(DP)接口的核心技术架构,重点剖析了其三大功能模块:承载视频/音频数据洪流的Main-Link主链路、负责链路训练与设备控制的AUX CH辅助通道,以及实现智能交互的HPD热插拔检测。文章详细阐述了主链路的可伸缩Lane配置、嵌入式时钟与数据成帧机制,以及辅助通道在设备发现、动态优化信号质量(链路训练)中的关键作用,揭示了DP接口实现高效率与灵活性的设计哲学。

weixin_29267307的博客 489

POJ #3624 Charm Bracelet 深入理解01背包以及其优化

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 theN(1 ≤N≤ 3,402) available c...

aibin6833的博客 405

Windows平台无人机仿真:从零搭建SITL环境与QGC联调

本文详细指导了在Windows平台上从零搭建无人机软件在环(SITL)仿真环境,并与QGroundControl(QGC)进行联调的完整流程。通过使用Cygwin工具链,开发者可以在没有实体硬件的情况下,模拟运行ArduPilot飞控,并通过MAVLink协议连接QGC地面站进行全功能测试,为无人机软件开发提供了一个安全、经济的虚拟沙盒环境。

weixin_29239279的博客 409

POJ——3624 Balanced Lineup(线段树入门——区间最值问题)

原题链接:http://poj.org/problem?id=3264 每天挤奶时,农夫John的N头奶牛(1≤N≤50,000头)总是按照相同的顺序排列。一天,农夫约翰决定和几头牛组织一场极限飞盘游戏。为了简单起见,他将从挤奶阵容中挑选一系列连续的奶牛来玩这个游戏。然而,为了让所有的奶牛都能玩得开心,它们的身高不应该相差太多。 农民John列出了Q(1≤Q≤200,000)头奶牛的身高(1≤身高≤1,000,000)。对于每一组,他希望您确定组中最矮和最高的牛之间的身高差异。 Input 第一行:两个空

pursuit的博客 655

STM32-CubeMx-HAL库-串口空闲中断+DMA——利用HAL_UARTEx_ReceiveToIdle_DMA实现不定长数据接收

STM32-CubeMx-HAL库-串口空闲中断+DMA——利用HAL_UARTEx_ReceiveToIdle_DMA实现不定长数据接收

weixin_43864631的博客 1万+

轨迹优化 | 图解欧氏距离场与梯度场算法(附ROS C++/Python实现)

距离场在运动规划中则常用于地图建模和轨迹梯度优化。本文图解欧氏距离场EDT的算法原理,并基于双线性插值给出欧氏梯度场的公式推导,并给出ROS C++和Python的算法实现加深理解

FRIGIDWINTER的博客 4646

POJ3624(背包问题)

  1、题目链接地址   http://poj.org/problem?id=3624   2、源代码 #include<iostream> using namespace std; #define MAXN 3403 //物品的最大数量 #define MAXM 12881 //重量的上限 int max(int x, int y) { if (x...

weixin_30670925的博客 228

华为OD机试双机位C卷-FLASH坏块监测系统(Py/Java/C/C++/Js/Go)

华为OD机试(机考)双机位C卷 【FLASH坏块监测系统】,提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - FLASH坏块监测系统。

qq_45776114的博客 1928

poj3624java_01背包问题:POJ3624

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

weixin_33120053的博客 946

NTscan扫描工具

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

深度学习工具包 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'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('DeepLearnToolbox'));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('state',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'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',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 = 'sigm';%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, 'Too big error');```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('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';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)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';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, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% 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'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 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, 'Too big error');```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('state',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, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',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, 'Too big error');%% ex3 neural net with dropoutrand('state',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, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % 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, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % 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, 'Too big error');%% 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('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % 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, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

poj - 3624(01背包的常数优化)

poj-3624 01背包: (1)二维数组表示dp[i][j]表示对第i个物品进行操作后,j大小的背包体积所能得到的最大价值。 所以每次对物品i操作时的状态转移方程为:dp[i][j] = MAX(dp[i-1][j],dp[i-1][j-a[i]]+b[i]); 表示选与不选物品i。 伪代码: for(i = 1~n) for(j = ai~m) dp...

积少成多,水滴石穿 487

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

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

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

动态规划--(01背包 poj3624 )

关于背包问题: 众所皆知,这里讲给出关于背包问题的一些简介: 一个旅行者准备随身携带一个背包. 可以放入背包的物品有n 种, 每种物品的重量和价值分别为 wj , vj . 如果背包的最大重量限制是 b, 怎样选择放入背包的物品以使得背包的价值最大?  题目就是这么简单: 先思考一个问题:就是每种物品可以重复选择,这种要怎么解决:

Randyhe_的博客 1684

POJ 3624 Charm Bracelet(01背包)

POJ 3624 Charm Bracelet(01背包) http://poj.org/problem?id=3624 题意:给你N个物品,每个具有Wi重量和Di价值,问你在不超过M的总重量前提下,能获得的最大价值是多少? 分析:明显的01背包问题。 令d[i][j]=x表选择完前i个物品后,总重量不超过j的前提下能获得的最大价值为x。 则d[i][j] = max( d[i-1][j

code 1073

POJ1976和POJ3624《01背包,动态规划》详细讲解,acm新手快来看看

poj1976和poj3624《动态规划,01背包》经典类型 详细讲解,acm新手快来

csl784513390的博客 1860

一维01背包 POJ3624

集训期间学会了动态规划的01背包,想去刷几道水题看看代码有没有问题,没想到遇到POJ3624,我原来的二维背包因为数据太大而不能AC,然后我到网上查看一下别人的方法,才看见,背包问题可以用一维!仔细想一下,对啊,这道题,用一维数组更新其值就可以了。于是重写代码,AC。代码如下: #include <stdio.h> #include <string.h> #def...

weixin_30790841的博客 86

POJ.3624 Charm Bracelet(DP 01背包)

POJ.3624 Charm Bracelet(DP 01背包)题意分析裸01背包代码总览#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 13000 #define nnmax 3500 using namespace std; int dp[nmax]; int w

Pengwill's Blog 310

POJ 3628 Bookshelf2 / POJ 3624 Charm Bracelet / POJ 1384 初涉01背包与完全背包

都是最基本的01背包,题意就不讲了。 01背包的状态转移方程,2维:dp[ i ][ j ] = max{dp[ i -1 ][ j ] , dp[ i-1][ j-w] + p};      1维:dp[ i ] = max{dp[i] , dp[i-w] + p}; 1维时要从大向小枚举,若从小向大枚举则变成了完全背包。 POJ 3624  #include #incl

自在飞花 1054

【常规的01背包 POJ3624 UVA562 HDU2546 HDU3466 poj1745】

POJ3624 有N个物品,分别有不同的重量Wi和价值Di,Bessie只能带走重量不超过M的物品,要是总价值最大,并输出总价值 //#include &lt;bits/stdc++.h&gt; #include &lt;iostream&gt; #define X 10005 #define inf 0x3f3f3f3f #define PI 3.1415926535897932384626...

sxy201658506207的博客 277

POJ 3624 01背包问题

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

从此爱上猫 268

01背包问题 poj 3624

理解01背包问题,首先要从二维数组的开始。二维数组的理解之后,优化成为一维,就是轻而易举的事了。 01背包动态规划的转移公式: 当考虑第i件物品的时候,背包能装得下的话, dp(i,j)=max{dp(i-1,j),dp(i-1,j-w[i])+v[i]} 如果背包装不下第i件物品的话 dp(i,j)=dp(i-1,j) package p3624; import java.io.F

Mason's Blog 2958

poj 3624 dp-01背包

poj 3624 类型为dp-01背包 初学背包 找了点背包的题目做做 题目大概意思就是能够带下的范围内的首饰 增加最大的魅力值 而且每种首饰只能带一种 显然是01背包 所承受重量为 背包的容量 每个首饰的重量和增加的魅力值为其大小和价值 直接 for ( int i = 0; i n; i ++){ for (

x___song的专栏 629
上一篇: hdu 2159(二维完全背包)
下一篇: poj 1252(完全背包)
真的好难
博客等级 码龄12年 5粉丝 207原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值