leetcode377
public class Solution {
private int[] dp;
public int CombinationSum4(int[] nums, int target)
{
dp = new int[target + ];
for (int i = ; i < dp.Length; i++)
{
dp[i] = -;
}
dp[] = ;
return helper(nums, target);
}
private int helper(int[] nums, int target)
{
if (dp[target] != -)
{
return dp[target];
}
int res = ;
for (int i = ; i < nums.Length; i++)
{
if (target >= nums[i])
{
res += helper(nums, target - nums[i]);
}
}
dp[target] = res;
return res;
}
}
https://leetcode.com/problems/combination-sum-iv/#/description
leetcode377的更多相关文章
- [Swift]LeetCode377. 组合总和 Ⅳ | Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- leetcode377 Combination Sum IV
思路: dp. 实现: class Solution { public: int combinationSum4(vector<int>& nums, int target) { ...
随机推荐
- Centos 查看版本
# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)
- SpringBoot发布到独立的tomcat中运行
在此文基础上 Eclipse下利用Maven创建SpringBoot的Restful风格程序 spring-boot默认提供内嵌的tomcat,所以打包直接生成jar包,用java -jar命令就可以 ...
- Struts2学习(1)
struts2概述 1.struts2框架应用javaee三层结构中web层框架. 2.strut2框架在struts1和webwork基础之上发展全新的框架. 3.struts2解决的问题: 4.版 ...
- 阿里云分布式缓存OCS与DB之间的数据一致性
[分布式系统的数据一致性问题] OCS概要介绍 据AlertSite网络分析公司表示,Facebook的响应时间在2010年平均为1秒钟,到2011年中期已提高到了0.73秒.对比来看,响应时间占 ...
- git,npm,bower设置代理地址
我們先假設代理伺服器的位址為: http://10.0.0.1:8080 設定 Git 使用代理伺服器 輸入兩行指令即可設定完畢: git config --global https.proxy ht ...
- 初识Linux--虚拟机下安装Ubuntu16
最近接收到任务,说是下半年可能要搞全文检索.听到后顿时炸锅了,一方面是对新技术的兴奋,另一方面,我TM连Linux都不会玩,怎么搞全文检索.怀揣着对开源世界的无线向往(恐惧),我决定试水Linux. ...
- canvas基础学习(一)
一.概述 canvas它和其它的HTML5标签的使用基本一致,但是它相当于在浏览器中建立一个画布,可以再这个画布上画图.创建动画甚至是3D游戏.由于canvas要适配不同终端的分辨率,所以尽可能的在标 ...
- sql-多表查询JOIN与分组GROUP BY
一.内部连接:两个表的关系是平等的,可以从两个表中获取数据.用ON表示连接条件 SELECT A.a,B.b FROM At AS A INNER JOINT Bt AS B ON A.m=B.n ...
- C语言编译全过程
编译的概念:编译程序读取源程序(字符流),对之进行词法和语法的分析,将高级语言指令转换为功能等效的汇编代码,再由汇编程序转换为机器语言,并且按照操作系统对可执行文件格式的要求链接生成可执行程序. ...
- CodeForces - 794C:Naming Company(博弈&简单贪心)
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...