类似BackpackII问题

     static int maximize_loot(int[] gold, int[] silver) {
int[][] res = new int[gold.length+silver.length+1][10001];
res[0][0] = 0;
for (int i=1; i<=gold.length; i++) {
for (int j=0; j<=10000; j++) {
res[i][j] = Math.max(res[i-1][j], (j>=gold[i-1]? res[i-1][j-gold[i-1]]+10*gold[i-1] : 0));
}
}
for (int i=1; i<=silver.length; i++) {
for (int j=0; j<=10000; j++) {
res[i+gold.length][j] = Math.max(res[i+gold.length-1][j], (j>=silver[i-1]? res[i+gold.length-1][j-silver[i-1]]+1*silver[i-1] : 0));
}
}
int maxVal = 0;
for (int k=0; k<=10000; k++) {
maxVal = Math.max(maxVal, res[gold.length+silver.length][k]);
}
return maxVal; }

VMware Coding Challenge: The Heist的更多相关文章

  1. VMware Coding Challenge: Removing Duplicates Entries

    static LinkedListNode removeDuplicates(LinkedListNode list) { LinkedListNode cur = list; HashSet< ...

  2. VMware coding Challenge: Coin Toss Betting

    static int CoinTossEndAmount(int betAmount, String coinTossResults) { if (betAmount <=0 || coinTo ...

  3. VMware coding Challenge:Date of Weekday

    这道题再次证明了这种细节的题目,画个图容易搞清楚 import java.util.Scanner; public class Solution2 { static int DateOfWeekday ...

  4. VMware Coding Challenge: Possible Scores && Summary: static

    Combination Sum I 那道题的变体 /* * Complete the function below. */ static int is_score_possible(int score ...

  5. VMware coding Challenge

    思路:这道题要观察,举个例子,1 2 * * 3 * 4  5 * * 6 7 * 8 * *, 用Stack,先序遍历,遇到数字就入栈,如果遇到 * *,说明栈顶节点是叶子节点,一条根到叶子的路径这 ...

  6. poj-2514-模拟

    http://poj.org/problem?id=2514 Ridiculous Addition Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. amazon interview

    I'll be sitting for an Amazon interview in 3 months. Which website should I use to practice: SPOJ, H ...

  8. 22. CTF综合靶机渗透(十五)

    靶机说明: Game of Thrones Hacking CTF This is a challenge-game to measure your hacking skills. Set in Ga ...

  9. 24 Days Of JavaScript mas

    24 Days Of JavaScript mas Level up your JavaScript skills with a daily coding challenge from Decembe ...

随机推荐

  1. LeetCode 17 Letter Combinations of a Phone Number (电话号码字符组合)

    题目链接 https://leetcode.com/problems/letter-combinations-of-a-phone-number/?tab=Description HashMap< ...

  2. Atom使用插件精选

    小颖之前公司的大哥推荐小颖用的编辑器是atom,之前都是他给小颖了一个atom插件安装列表,小颖电脑出了点问题,所以后来小颖把那弄丢了,小颖重装atom后,就不知道要安装什么插件,所以也百度了很多,今 ...

  3. MVC验证

    前言 MVC自己的验证机制,通过一个案例记录学习的成果. 首先,model代码如下: public class Students    {        [Display(Name = "I ...

  4. Memcached概念、作用、运行原理、特性、不足简单梳理(1)

    大家可能对memcached这种产品早有了解,或者已经应用在自己的网站中了,但是也有一些朋友从来都没有听说过或者使用过.这都没什么关系,本文旨在从各个角度综合的介绍这种产品,尽量深入浅出,如果能对您现 ...

  5. 【CF887E】Little Brother 二分+几何

    [CF887E]Little Brother 题意:给你n个圆和一条线段,保证圆和圆.圆和线段所在直线不相交,不相切,不包含.求一个过线段两端点的圆,满足不和任何圆相交(可以相切.包含).问圆的最小半 ...

  6. Thinkphp框架下(同服务器下)不同二级域名之间session互通共享设置

    在Thinkphp框架下根目录打开index.php 在头部加入如下代码即可: //入口文件 define('DOMAIN','abc.com');//abc.com换成自己的跟域名 //以下两行是为 ...

  7. java的前缀自增自减和后缀自增自减

    2.前缀自增自减法(++a,--a): 先进行自增或者自减运算,再进行表达式运算. 3.后缀自增自减法(a++,a--): 先进行表达式运算,再进行自增或者自减运算 实例: 实例 public cla ...

  8. C++虚函数virtual,纯虚函数pure virtual和Java抽象函数abstract,接口interface与抽象类abstract class的比较

    由于C++和Java都是面向对象的编程语言,它们的多态性就分别靠虚函数和抽象函数来实现. C++的虚函数可以在子类中重写,调用是根据实际的对象来判别的,而不是通过指针类型(普通函数的调用是根据当前指针 ...

  9. poj3259 Wormholes【最短路-bellman-负环】

    While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole ...

  10. Codeforces 752C - Santa Claus and Robot - [简单思维题]

    题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...