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. 安装,配置webpack.

    1.下载node.js 2.在需要用到webpack的项目下打开命令窗口运行npm init生成package.js 3.安装webpack,使用npm install webpack --save- ...

  2. BZOJ3671/UOJ6 [Noi2014]随机数生成器

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  3. Spring的DI初步

    DI:依赖注入 第一个DEMO:域属性注入 java类:(Car类和Stu类,学生有一辆小汽车) package cn.dawn.day02di; /** * Created by Dawn on 2 ...

  4. 理解collate Chinese_PRC_CI_AS

    我们在create table时经常会碰到这样的语句,例如:password nvarchar(10)collate chinese_prc_ci_as null,那它到底是什么意思呢?不妨看看下面: ...

  5. hzau 1207 Candies

    1207: Candies Time Limit: 2 Sec  Memory Limit: 1280 MBSubmit: 223  Solved: 31[Submit][Status][Web Bo ...

  6. [项目部署] CentOs7 安装 MySQL/Tomcat/JDK 笔记

    0.安装 MySQL cd /usr/local/ # 新增yum源 rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-.no ...

  7. ubuntu16.04下安装配置深度学习环境(Ubuntu 16.04/16.10+ cuda7.5/8+cudnn4/5+caffe)

    主要参照以下两篇博文:http://blog.csdn.net/g0m3e/article/details/51420565   http://blog.csdn.net/xuzhongxiong/a ...

  8. vue配置stylus

    首先Vue-init webapck 随便一个name vue项目创建好之后 cnpm i  (利用淘宝镜像) cnpm i stylus stylus-loader -D 进行安装和配置 styl常 ...

  9. JSP学习笔记(九十):eclipse3.4中建立控制台程序

    1.控制台程序的建立 File->New->Application Client Project,勾选上Create a default Main class 找到Main.java,修改 ...

  10. canvas基础学习(三)

    一.图片加载控件 在canvas效果制作中常常要使用多张图片,为了提高用户体验,需要给用户提供一个图片加载中的过度页面效果.过度效果,我在项目中使用的是Sonic.js,它在git上的地址为https ...