VMware Coding Challenge: The Heist

类似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的更多相关文章
- VMware Coding Challenge: Removing Duplicates Entries
static LinkedListNode removeDuplicates(LinkedListNode list) { LinkedListNode cur = list; HashSet< ...
- VMware coding Challenge: Coin Toss Betting
static int CoinTossEndAmount(int betAmount, String coinTossResults) { if (betAmount <=0 || coinTo ...
- VMware coding Challenge:Date of Weekday
这道题再次证明了这种细节的题目,画个图容易搞清楚 import java.util.Scanner; public class Solution2 { static int DateOfWeekday ...
- VMware Coding Challenge: Possible Scores && Summary: static
Combination Sum I 那道题的变体 /* * Complete the function below. */ static int is_score_possible(int score ...
- VMware coding Challenge
思路:这道题要观察,举个例子,1 2 * * 3 * 4 5 * * 6 7 * 8 * *, 用Stack,先序遍历,遇到数字就入栈,如果遇到 * *,说明栈顶节点是叶子节点,一条根到叶子的路径这 ...
- poj-2514-模拟
http://poj.org/problem?id=2514 Ridiculous Addition Time Limit: 1000MS Memory Limit: 65536K Total S ...
- amazon interview
I'll be sitting for an Amazon interview in 3 months. Which website should I use to practice: SPOJ, H ...
- 22. CTF综合靶机渗透(十五)
靶机说明: Game of Thrones Hacking CTF This is a challenge-game to measure your hacking skills. Set in Ga ...
- 24 Days Of JavaScript mas
24 Days Of JavaScript mas Level up your JavaScript skills with a daily coding challenge from Decembe ...
随机推荐
- wps 批量调整图片大小 宏
Sub 批量调整图片大小() ' ' 批量修改图片 Macro ' 宏由 zxz 录制,时间: 2014/10/29 '批量调整图片大小,避免图片太大显示不完全 '循环图片集合 For Each iS ...
- C# 拆箱与装箱及优化
1.概念 装箱在值类型向引用类型转换时发生,在堆中分配. 拆箱在引用类型向值类型转换时发生. 2.装箱拆箱的过程 //这行语句将整型常量1赋给object类型的变量obj:众所周知常量1是值类型,值类 ...
- Excel 2007表格内输入http取消自动加上超链接的功能
经常使用Excel表格工作的也许会发现,当我们在表格内输入http://XXXX时,默认情况下都会自动加上超链接,如下: 当我们点击域名准备编辑修改时,往往都会调用浏览器转到该域名之下,达不到编辑修改 ...
- linux常用命令之scp详解
使用scp的前提: 1.服务端启动了sshd服务 2.是本地和远程两端的系统都必须要有scp这个命令.即openssh-clients软件包 [安装方法] [root@ ~]# yum install ...
- 【CF845F】Guards In The Storehouse 插头DP
[CF845F]Guards In The Storehouse 题意:一个n*m的房间,每个格子要么是障碍要么是空地.对于每个空地你可以选择放或者不放守卫.一个守卫能保护到的位置是:他右面的一行空地 ...
- IOS根据两个经纬度计算相距距离
//第一种苹果自带的 CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self double ...
- 在线工具-程序员的工具箱-在线Cron表达式生成器
在线Cron表达式生成器 http://cron.qqe2.com/ 在线工具 - 程序员的工具箱 https://tool.lu/
- iOS - Charles抓包数据
一.Charles Charles破解版下载地址点我 1.1 Charles主要的功能 .截取Http.Https网络请求内容 .支持修改网络请求参数,方便调试 .支持网络请求的截取 并动态修改 1. ...
- R的any和all
> x<-1:10 > any(x>8) [1] TRUE > all(x>8) [1] FALSE
- DLRS(近三年深度学习应用于推荐系统论文汇总)
Recommender Systems with Deep Learning Improving Scalability of Personalized Recommendation Systems ...