LintCode刷题笔记-- BackpackIII
标签:动态规划
问题描述:
Given n items with size Ai and value Vi, and a backpack with size m. What's the maximum value can you put into the backpack?
public int backPackII(int m, int[] A, int V[]) {
// write your code here
int[][] dp = new int[A.length+1][m+1];
dp[0][0] = 0;
for(int i=1; i<=A.length; i++){
for(int j = 0; j<=m; j++){
if(j<A[i-1]){
dp[i][j]=dp[i-1][j];
}else if(j>=A[i-1]){
dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-A[i-1]]+V[i-1]);
}
}
}
return dp[A.length][m];
}
LintCode刷题笔记-- BackpackIII的更多相关文章
- lintcode刷题笔记(一)
最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. L ...
- LintCode刷题笔记-- LongestCommonSquence
标签:动态规划 题目描述: Given two strings, find the longest common subsequence (LCS). Your code should return ...
- LintCode刷题笔记-- PaintHouse 1&2
标签: 动态规划 题目描述: There are a row of n houses, each house can be painted with one of the k colors. The ...
- LintCode刷题笔记-- Maximum Product Subarray
标签: 动态规划 描述: Find the contiguous subarray within an array (containing at least one number) which has ...
- LintCode刷题笔记-- Maximal Square
标签:动态规划 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing a ...
- LintCode刷题笔记-- Edit distance
标签:动态规划 描述: Given two words word1 and word2, find the minimum number of steps required to convert wo ...
- LintCode刷题笔记-- Distinct Subsequences
标签:动态规划 题目描述: Given a string S and a string T, count the number of distinct subsequences of T in S. ...
- LintCode刷题笔记-- BackpackIV
标签: 动态规划 描述: Given an integer array nums with all positive numbers and no duplicates, find the numbe ...
- LintCode刷题笔记-- BackpackII
标记: 动态规划 问题描述: Given n items with size Ai, an integer m denotes the size of a backpack. How full you ...
随机推荐
- 01-python 学习第一天
今天是学习python语言的第一天,通过中国大学MOOC网的相关课程和其他在线教程,对python 语言有了初步的认识.今天我记住了<人生苦短,Python是岸>这句话.如果有人学习,建议 ...
- Frame用navigate导航到新页面后导航条隐藏的方法
设置Frame的NavigationUIVisibility="Hidden"
- parameter–precharge, tRCD and tRAS
以下描述来自wikipeida : https://en.wikipedia.org/wiki/Synchronous_dynamic_random-access_memory 几点总结: (1) 每 ...
- Ajax.NET-Professional
https://github.com/michaelschwarz/Ajax.NET-Professional Ajax.NET Professional Ajax.NET Professional ...
- 转:linux select 多路复用机制
源地址:http://blog.csdn.net/turkeyzhou/article/details/8609360 2013-02-25 14:18 442人阅读 评论(1) 收藏 举报 目录 ...
- pycharm 安装与激活
---恢复内容开始--- 环境:Windows 专业版 1.下载安装 1.到官网下载专业版(专业版功能更全(但要激活码),社区版免费) 2.下载完后双击.exe 文件进行安装 NEXT 下一步 NEX ...
- PAT甲级——A1039 Course List for Student
Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists o ...
- 再谈MFC学习——模态对话框的数据传递
学习c++的目的就是为了使用封装好的类.而最最经典的封装类当然是微软的MFC窗体程序类. 学习MFC编程之前要学习c++的主要知识,掌握c++的基本编程思想. 以下就看下我学习的MFC模态对话框的数据 ...
- 安装配置flask环境
安装 Flask 好的,让我们开始吧! 现在我们必须开始安装 Flask 以及一些我们会用到的扩展.我首选的方式就是创建一个虚拟环境,这个环境能够安装所有的东西,而你的主 Python 不会受到影响. ...
- hbase设计方案1
好的方案应该挺多的,比如:可以将[日.周.月]以3,2,1来表示(拼接到ROW_KEY中){离线跑job时候,可以分为月job(每月末run一下,周job(每周末run一下),日job(每天run一下 ...