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. mongo管理工具

    启动 D:\Program Files\MongoDB\Server\3.4\bin\mongod.exe --dbpath d:\data\db 还原 D:\Program Files\MongoD ...

  2. 抢凳子日数据sql

    --先找到档期select * from hv_item_info a where a.report_begdate > '2016-07-28' and a.report_begdate &l ...

  3. thinkphp 添加 修改删除

    在 MainController.class.php 添加 public function zhuCe() { //时间两个逻辑 // 1 显示页面 2向数据库添加 if(empty($_POST)) ...

  4. extern关键字

    1.extern "C" void func(){...} extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其 ...

  5. 串口控RGB三色灯

    本文由博主原创,如有不对之处请指明,转载请说明出处. /********************************* 代码功能:串口控RGB三色灯 使用函数: Serial.flush(); / ...

  6. 第四十一章 微服务CICD(3)- jenkins + gitlab + webhooks + publish-over-ssh(1)

    一.作用 使用webhooks来实现当git客户端push代码到gitlab后,jenkins会立即去gitlab拉取代码并构建. 二.步骤 1.安装插件 ruby_runtime(Hook插件依赖于 ...

  7. grunt配置太复杂?使用Qbuild进行文件合并、压缩、格式化等处理

    上次简单介绍了下Qbuild的特点和配置,其实实现一个自动化工具并不复杂,往简单里说,无非就是筛选文件和处理文件.但Qbuild的源码也并不少,还是做了不少工作的. 1. 引入了插件机制.在Qbuil ...

  8. Cordova系列(一)

    1.安装 这里推荐用npm安装cordova,至于npm的安装,网上有很多的.打开命令行,输入 npm install -g cordova 这里就安装了好了最新版的cordova,虽然绝大多数会成功 ...

  9. 总结JS 常用函数

    希望本文总结的内容能给各位看官带来焕然一新的感觉.另外,如果你们有什么值得推荐的js技巧,欢迎在评论中补充,我可以收纳在本文中. PS:此文档会持续新增内容. Ajax请求 jquery ajax函数 ...

  10. [PHP]OOP两类写法的性能对比

    在PHP的OOP中我们有常见两种方法调用,对象调用和静态调用. 下面是一个简单的测试来比较它们的细微差异. /** * 对象初始化 -> 调用:objectCall.php * * 测试调用50 ...