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) { ...
随机推荐
- YII2笔记之一
安装advanced:执行init 执行yii.bat 创建数据库 修改common/config/main-local.php中的db配置 执行migratebasic:web目录是可以被外部直 ...
- QT国际化示例, 检测系统语言,设置适合语言,按键切换显示语言
1.效果如下图,开启就自动检测系统语言,选择系统语言显示, UI有控件设置,在中文和英文之间切换.. 2. 源码 dialog.h #ifndef DIALOG_H #define DIALOG_H ...
- R中读取EXCEL 数据的方法
最近初学R语言,在R语言读入EXCEL数据格式文件的问题上遇到了困难,经过在网上搜索解决了这一问题,下面归纳几种方法,供大家分享: 第一:R中读取excel文件中的数据的路径: 假定在您的电脑有一个e ...
- java导包
下载响应的zip文件,就可以导入了,导入src目录也是可以的.
- 智课雅思词汇---十七、前綴il-, in-, ir-, im-有什麼關係
智课雅思词汇---十七.前綴il-, in-, ir-, im-有什麼關係 一.总结 一句话总结:这几个长得非常像,并且意思也非常像 1.前綴il-, in-, ir-, im-是什麼意思? 前缀:i ...
- 51nod 1267 二分
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1267 1267 4个数和为0 基准时间限制:1 秒 空间限制:13107 ...
- 插入排序—希尔排序(Shell`s Sort)原理以及Java实现
希尔排序是1959 年由D.L.Shell 提出来的,相对直接排序有较大的改进.希尔排序又叫缩小增量排序 基本思想: 先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录 ...
- Linq练习题
1 . 查询 Student 表中的所有记录的 Sname . Ssex 和 Class 列. select sname,ssex,class from student Linq: from ...
- 分布式_理论_08_Consistent Hash(一致性哈希算法)
一.前言 五.参考资料 1.分布式理论(八)—— Consistent Hash(一致性哈希算法)
- linux install JDK
安装JDK 下载jdk-6u23-linux-i586.bin,samba,FTP cd /usr/local/src/ wget http://www.aminglinux.com/bbs/data ...