原题链接

题意:

给一个非整数,算出其最少可以由几个完全平方数组成(1,4,9,16……)

思路:

可以得到一个状态转移方程

 dp[i] = min(dp[i], dp[i - j * j] + );
代码如下:
Runtime: 60 ms, faster than 69.83% 有点慢
class Solution
{
public:
int numSquares(int n)
{
int dp[n + ]; for (int i = ; i <= n; i++)
{
dp[i] = i;
for (int j = ; j * j <= i; j++)
{
dp[i] = min(dp[i], dp[i - j * j] + );
}
}
return dp[n];
}
};

[leetcode] #279 Perfect Squares (medium)的更多相关文章

  1. leetcode@ [279]Perfect Squares

    https://leetcode.com/problems/perfect-squares/ Given a positive integer n, find the least number of ...

  2. [LeetCode] 279. Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  3. (BFS) leetcode 279. Perfect Squares

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  4. [LeetCode 279.] Perfect Squres

    LeetCode 279. Perfect Squres DP 是笨办法中的高效办法,又是一道可以被好办法打败的 DP 题. 题目描述 Given a positive integer n, find ...

  5. [LeetCode] 0279. Perfect Squares 完全平方数

    题目 Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9 ...

  6. 【LeetCode】279. Perfect Squares 解题报告(C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 四平方和定理 动态规划 日期 题目地址:https: ...

  7. 【leetcode】Perfect Squares (#279)

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  8. 279. Perfect Squares

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  9. 279. Perfect Squares(动态规划)

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

随机推荐

  1. 解决xp越来越慢的办法(其中有些自动备份的功能)

    1.减少磁盘空间占用2.终止不常用的系统服务3.安全问题4.另外一些技巧 首先问一下,你是不是很想激活XP,不...准确的说你是不是想在ms的站上能够升级.如果答案是肯定的话,那我们就先来探讨一下安装 ...

  2. jsp中的指令与动作

    JSP中的三种命令指令分别是page.include.taglib JSP中的动作元素包括:include.forward.useBean.getProperty.setProperty.plugin ...

  3. Qt 中C++ static_cast 和 reinterpret_cast的区别(static_cast是隐式类型转换,会有数据损失,reinterpret_cast是底层二进制转换,没有数据损失)

    1.C++中的static_cast执行非多态的转换,用于代替C中通常的转换操作.因此,被做为隐式类型转换使用.比如: int i; float f = 166.7f; i = static_cast ...

  4. SYN2136型 北斗NTP网络时间服务器

    SYN2136型  北斗NTP网络时间服务器 北斗NTP网络时间服务器时间服务器使用说明视频链接: http://www.syn029.com/h-pd-109-0_310_36_-1.html 请将 ...

  5. Nginx+Keepalived部署流程

    环境介绍 1)LB01 Hostname:lb01.example.com VIP:192.168.3.33(eth0:0) IP:192.168.3.31(eth0) OS:Centos 7 2)L ...

  6. 08 JS的事件流的概念(重点)

    在学习jQuery的事件之前,大家必须要对JS的事件有所了解.看下文 事件的概念 HTML中与javascript交互是通过事件驱动来实现的,例如鼠标点击事件.页面的滚动事件onscroll等等,可以 ...

  7. Kafka 学习之路(一)—— Kafka简介

    一.简介 Apache Kafka是一个分布式的流处理平台.它具有以下特点: 支持消息的发布和订阅,类似于RabbtMQ.ActiveMQ等消息队列: 支持数据实时处理: 能保证消息的可靠性投递: 支 ...

  8. spring 5.x 系列第11篇 —— 整合memcached (xml配置方式)

    文章目录 一.说明 1.1 XMemcached客户端说明 1.2 项目结构说明 1.3 依赖说明 二.spring 整合 memcached 2.1 单机配置 2.2 集群配置 2.3 存储基本类型 ...

  9. Redis 在java中的使用(登录验证,5分钟内连续输错3次密码,锁住帐号,半小时后解封)(三)

    在java中使用redis,做简单的登录帐号的验证,使用string类型,使用redis的过期时间功能 1.首先进行redis的jar包的引用,因为用的是springBoot,springBoot集成 ...

  10. ASP.NET Core Web API中使用Swagger

    本节导航 Swagger介绍 在ASP.NET CORE 中的使用swagger   在软件开发中,管理和测试API是一件重要而富有挑战性的工作.在我之前的文章<研发团队,请管好你的API文档& ...