思路:

dp。

实现:

 class Solution
{
public:
int combinationSum4(vector<int>& nums, int target)
{
if (nums.empty()) return target == ;
vector<int> dp(target + , );
dp[] = ;
vector<int> tmp(nums.begin(), nums.end());
sort(tmp.begin(), tmp.end());
int n = tmp.size();
for (int i = ; i <= target; i++)
{
for (int j = ; tmp[j] <= i && j < n; j++)
{
dp[i] += dp[i - tmp[j]];
}
}
return dp[target];
}
};

leetcode377 Combination Sum IV的更多相关文章

  1. Combination Sum | & || & ||| & IV

    Combination Sum | Given a set of candidate numbers (C) and a target number (T), find all unique comb ...

  2. LC 377. Combination Sum IV

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

  3. [LeetCode] Combination Sum IV 组合之和之四

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

  4. 39. Combination Sum + 40. Combination Sum II + 216. Combination Sum III + 377. Combination Sum IV

    ▶ 给定一个数组 和一个目标值.从该数组中选出若干项(项数不定),使他们的和等于目标值. ▶ 36. 数组元素无重复 ● 代码,初版,19 ms .从底向上的动态规划,但是转移方程比较智障(将待求数分 ...

  5. [LeetCode] 377. Combination Sum IV 组合之和之四

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

  6. [LeetCode] 377. Combination Sum IV 组合之和 IV

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

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

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

  8. 377. Combination Sum IV

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

  9. Leetcode 377. Combination Sum IV

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

随机推荐

  1. 洛谷 P1457 城堡 The Castle

    P1457 城堡 The Castle 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特别的礼物:一张“幸运爱尔兰”(一种彩票).结果这 ...

  2. codevs 3498 小木棍

    3498 小木棍  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 乔治有一些同样长的小木棍,他把这些木棍随意 ...

  3. Ubuntu 16.04安装RabbitVCS替代TortoiseSVN/TortoiseGit

    RabbitVCS官网:http://www.rabbitvcs.org/easonjim 1.添加PPA源 sudo add-apt-repository ppa:rabbitvcs/ppa 如果导 ...

  4. mybatis collection标签和association标签(一对多,一对一)转载

    mybatis 一对一与一对多collection和association的使用   在mybatis如何进行一对一.一对多的多表查询呢?这里用一个简单的例子说明. 一.一对一 1.associati ...

  5. Port forwarding with xinetd Ask

    https://stackoverflow.com/questions/21716673/port-forwarding-with-xinetd --------------------------- ...

  6. python 区块链程序

    python 区块链程序 学习了:https://mp.weixin.qq.com/s?__biz=MzAxODcyNjEzNQ==&mid=2247484921&idx=1& ...

  7. http://www.cnblogs.com/sprinkle/

    http://www.cnblogs.com/sprinkle/ http://www.cnblogs.com/sprinkle/

  8. Android--Activity在跳转时携带数据

    首先看看两种传递方法演示样例:(一个简单姻缘计算器) 主Activity import android.os.Bundle; import android.app.Activity; import a ...

  9. 一个有趣的问题:ls -l显示的内容中total究竟是什么?

    当我们在使用ls -l的命令时,我们会看到例如以下类似的信息. 非常多人可能对于第一行的total 12的数值并非非常在意,可是你是否想过,它到底是什么意思? man中的说明,我们能够看出total的 ...

  10. CentOS 7 执行级别的切换

    CentOS 7 执行级别的切换 由命令行级别切换到窗体级别的命令未变:init 5或startx 由窗体级别切换到命令行级别的命令未变:init 3 新版本号的执行级别都定义在 /lib/syste ...