Problem Introduction

This problem is about implementing an algorithm for the knapsack without repetitions problem.

Problem Description

Task.In this problem, you are given a set of bars of gold and your goal is to take as much gold as possible into you bag. There is just one copy of each bar and for each bar you can either take it or not(hence you cannot take a fraction of a bar).

Input Format.The first line of the input contains the capacity \(W\) of a knapsack and the number \(n\) of bars of gold. The next line contains \(n\) integers \(w_0, w_1. \cdots, w_{n-1}\) defining the weights of the bars of gold.

Constraints.\(1 \leq W \leq 10^4\); \(1 \leq n \leq 300\); \(0 \leq w_0, \cdots, w_{n-1} \leq 10^5\).

Output Format.Output the maximum weight of gold that fits into a knapsack of capacity \(W\).

Sample 1.
Input:

10 3
1 4 8

Output:

9

Solution

[UCSD白板题] Take as Much Gold as Possible的更多相关文章

  1. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  2. [UCSD白板题] Maximize the Value of an Arithmetic Expression

    Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...

  3. [UCSD白板题] Compute the Edit Distance Between Two Strings

    Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...

  4. [UCSD白板题] Primitive Calculator

    Problem Introduction You are given a primitive calculator that can perform the following three opera ...

  5. [UCSD白板题] Points and Segments

    Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...

  6. [UCSD白板题] Number of Inversions

    Problem Introduction An inversion of a sequence \(a_0,a_1,\cdots,a_{n-1}\) is a pair of indices \(0 ...

  7. [UCSD白板题] Sorting: 3-Way Partition

    Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...

  8. [UCSD白板题] Majority Element

    Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...

  9. [UCSD白板题] Binary Search

    Problem Introduction In this problem, you will implemented the binary search algorithm that allows s ...

随机推荐

  1. MyBatis怎么防止SQL注入

    SQL注入是一种代码注入技术,用于攻击数据驱动的应用,恶意的SQL语句被插入到执行的实体字段中(例如,为了转储数据库内容给攻击者).[摘自] SQL injection - Wikipedia SQL ...

  2. Linux下JDK、Tomcat

    1.JDK的安装   1. 下载JDK 先查看Linux系统是多少位(32位/64位):getconf  LONG_BIT.再从JDK官网(http://www.oracle.com/technetw ...

  3. 未能正确加载“RoslynPackage”包

    一打开新建程序或者打开项目就报错,原因是安装的组件或者模板丢失或者有问题,在这一过程加载组件必定会产生错误,以下为解决方法: 1.重命名以下文件夹C:\Users\moonlight\Local Se ...

  4. 修改Arduino串口缓冲区大小(转)

    本帖节选自<Arduino程序设计基础>第二版5.1.6串口缓冲区       在之前的示例程序中,我们都是采用人工输入测试数据的方式检验程序效果,Arduino每接收到一次数据,就会将数 ...

  5. PLL失锁

    2016-07-05 现象:在低温(-30度以下)下,射频锁定信号出现周(大约20ms)期性高低电平的变化,由于MCU检测一次需要的时间很长(大于500ms), 大概总是检测不到失锁状态,所以不会出现 ...

  6. SVN服务器搭建之提交日志模版构建

    SVN服务器搭建之提交日志模版构建 日志提交有两种 一种是自己客户端设置提交日志模版,这个只适用于自己,没办法强制性运用到项目中,只能依照每个人的自觉性来处理. 第二种方法是SVN服务器设置提交日志模 ...

  7. js+cookie 购物车

    $(function () { //var ctx = new Ch(); //ctx.Clear(); //$.cookie(ctx.cookieName, ""); //ale ...

  8. 《VB语言程序设计(第3版)》总结

    我之前因学习昆仑通态的组态软件MCGS,用并学习过VB,还买了一本书<VB语言程序设计(第3版)>.现在在某公司实习,最近接触老的项目,又要用到VB.我就又把那本书大体看了一遍,并对其进行 ...

  9. 搭建高可用mongodb集群(二)—— 副本集

    在上一篇文章<搭建高可用MongoDB集群(一)——配置MongoDB> 提到了几个问题还没有解决. 主节点挂了能否自动切换连接?目前需要手工切换. 主节点的读写压力过大如何解决? 从节点 ...

  10. javascript设计模式(单体模式)

    主要内容: js中最基本.应用最广的模式就是单体模式,实现原理是将代码组织为一个逻辑单元,这个逻辑单元中的代码可以通过单一的变更进行访问,确保对象只存在一份实例. 单体模式的特点: 在网页中使用全局变 ...