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的更多相关文章

  1. [Swift]LeetCode377. 组合总和 Ⅳ | Combination Sum IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  2. leetcode377 Combination Sum IV

    思路: dp. 实现: class Solution { public: int combinationSum4(vector<int>& nums, int target) { ...

随机推荐

  1. Python显示百分比

    print(format(a/b,'.2%')) 显示两位小数的百分比显示

  2. scheduler configuration options

    Table 4.53. Description of scheduler configuration options Configuration option = Default value Desc ...

  3. c# 查找一个字符串在另一个字符串出现的次数

    方法一: string test = "FF FF FF FF 01 00 82 00 00 A2 00 00 FB 07 FF FF FF FF 01 00 82 00 00 A2 00 ...

  4. mac中的echo颜色输出

    mac: echo "\033[1;36mSister Lin Fall from the Sky\033[0m" ubuntu: echo -e "\e[1;36mSi ...

  5. Object.assign()与深拷贝(一)

    深拷贝与浅拷贝 所谓深拷贝与浅拷贝,是围绕引用类型变量的拷贝进行的讨论. 在ECMAScript中,变量分为基本类型和引用类型两种.其本质区别是不可变性,基本类型是不可变的,而引用类型是可变的. 所谓 ...

  6. Win7+VS2010下配置WTL开发环境

    一.今天Win7下刚装了VS2010,解压wtl81_12085.zip到C盘根目录,进入C:\wtl81_12085\AppWiz下,执行setup100.js提示向导安装成功. 在VS2010中新 ...

  7. 27 python 网络基础之网络协议

    一.操作系统基础 操作系统:(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才 ...

  8. 《Effective C++》——条款08:别让异常逃离析构函数

    考虑如下代码: class Widget{ public: ... ~Widget(){...}//假设这个可能吐出一个异常 }; void doSomething() { std::vector&l ...

  9. uva11489 - Integer Game(考思维,找规律)

    从S开始时只能是两种情况: 1.现在总和已经是3的倍数了,那么因为每人每次只能拿走一个数,要保持拿走之后依然是3的倍数,那么就只能拿3,6,9这类数,用num统计一下,看看num奇偶性就知道谁最后拿了 ...

  10. Boost 读写锁

    //#########测试多线程,读写锁,递归锁 #include <boost/thread.hpp> #include <boost/thread/recursive_mutex ...