416 Partition Equal Subset Sum 分割相同子集和
2024-09-07 14:49:14
详见:https://leetcode.com/problems/partition-equal-subset-sum/description/
C++:
class Solution {
public:
bool canPartition(vector<int>& nums)
{
int sum = accumulate(nums.begin(), nums.end(), 0);
if (sum % 2 == 1)
{
return false;
}
int target = sum / 2;
vector<bool> dp(target + 1, false);
dp[0] = true;
for (int i = 0; i < nums.size(); ++i)
{
for (int j = target; j >= nums[i]; --j)
{
dp[j] = dp[j] || dp[j - nums[i]];
}
}
return dp.back();
}
};
参考:http://www.cnblogs.com/grandyang/p/5951422.html
最新文章
- Linux Cmd Tool 系列之—script &; scriptreplay
- 解决Shiro注解无效的问题
- BZOJ4382 : [POI2015]Podział naszyjnika
- [Angularjs]国际化
- PHPCMS V9 学习总结
- OpenGL的GLUT初始化函数[转]
- C# 使用ping命令
- ssh-add命令
- [转] What is Ec/Io (and Eb/No)?
- recovery编译汉化
- React Native 初识
- 再看static数据成员
- .bash_profile与.bashrc和.profile的区分概念
- js连续赋值、指针
- Centos 6.5开启rsync同步
- P2757 导弹的召唤(数据加强)
- Android开发_TextView跑马灯
- 安装使用aria2下载百度网盘内容(转)
- 【JVM】查看JVM加载的类及类加载器的方法
- golang并发(1)介绍