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. Spring学习之xml配置Bean总结

    学习Spring时,我用的是Maven来管理jar包,先看看maven的pom.xml: pom.xml <project xmlns="http://maven.apache.org ...

  2. matplotlib两种画散点图的方式

    对于matplotlib.pyplot( as plt ) 先输入主体数据部分: import numpy as np import matplotlib.pyplot as plt X_train ...

  3. 安装rackspace private cloud --2 overview

    Target hosts 包含以下 network bridges: LXC internal lxcbr0: 必须的,自动生成,containers的外网连接,不连接到host上任何物理/逻辑接口, ...

  4. MySQL 体系结构和存储引擎

    数据库: 物理操作系统文件或其他形式文件类型的集合 实例: MySQL数据库向后台线程以及一个共享内存区组成,共享内存可以被运行的后台线程所共享 MySQL 数据库实例在某统上的表现就是一个进程. M ...

  5. xml获取指定节点的路径

    引用自http://www.w3school.com.cn/xpath/xpath_syntax.asp XPath 语法 Previous Page Next Page XPath 使用路径表达式来 ...

  6. JavaScript--收藏栏添加按钮,放大hdu题目字体

    觉得HDOJ的题目字体太小了,一波小操作 在收藏栏添加:添加网页->网址改为: javascript: void((function() { var element = document.get ...

  7. uva1605 - Building for UN(构造法)

    这道题构造出的结果很妙,考察思维能力.就两层,每层都n*n个格子,第一层第i行都放国家i,第二层第j列都放国家j. 需要注意的是ASCII中A至Z在a至z的前面(数字小),而且它们两组不挨着.所以需要 ...

  8. redis 双写一致性问题

    首先,缓存由于其高并发和高性能的特性,已经在项目中被广泛使用.在读取缓存方面,大家没啥疑问,都是按照下图的流程来进行业务操作. 但是在更新缓存方面,对于更新完数据库,是更新缓存呢,还是删除缓存.又或者 ...

  9. pair对组

    一.pair基本概念 对组(pair)将一对值组合成一个值,这一对值可以具有不同的数据类型,两个值可以分别用pair的两个公有函数first和second访问. 类模板:template <cl ...

  10. 纯JS实现房贷利率报表对比

    最近朋友买房,想计算下自己的房贷的还款情况,自己正好周末没事,从网上找来点代码修改,也算是对自己技术的巩固吧. 目前这个还只是个初级版本,暂时可以在PC上正常访问,将来会一步一步的把相继功能都加上的, ...