详见: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

最新文章

  1. Linux Cmd Tool 系列之—script &amp; scriptreplay
  2. 解决Shiro注解无效的问题
  3. BZOJ4382 : [POI2015]Podział naszyjnika
  4. [Angularjs]国际化
  5. PHPCMS V9 学习总结
  6. OpenGL的GLUT初始化函数[转]
  7. C# 使用ping命令
  8. ssh-add命令
  9. [转] What is Ec/Io (and Eb/No)?
  10. recovery编译汉化
  11. React Native 初识
  12. 再看static数据成员
  13. .bash_profile与.bashrc和.profile的区分概念
  14. js连续赋值、指针
  15. Centos 6.5开启rsync同步
  16. P2757 导弹的召唤(数据加强)
  17. Android开发_TextView跑马灯
  18. 安装使用aria2下载百度网盘内容(转)
  19. 【JVM】查看JVM加载的类及类加载器的方法
  20. golang并发(1)介绍

热门文章

  1. Visual Studio VS如何重置所有设置
  2. Office WORD里插入图片,嵌入型只能显示一半怎么办
  3. Deepin-安装php
  4. vue 自定义报警组件
  5. asp.net mvc的权限管理设计
  6. ./configure &amp;&amp; make &amp;&amp; make install详解 (转)
  7. xgboost python windows编译问题
  8. git 删除目录
  9. Flask采用Virtualenv+Supervisor+Nginx部署应用
  10. 1分钟看完 jQuery UI