当前位置: 首页 > news >正文

成都网站设计制作价格seo综合查询 站长工具

成都网站设计制作价格,seo综合查询 站长工具,平台推广方式方法是什么,做暧暖ox网站题目 完全平方数 给你一个整数 n ,返回 和为 n 的完全平方数的最少数量 。 完全平方数 是一个整数,其值等于另一个整数的平方;换句话说,其值等于一个整数自乘的积。例如,1、4、9 和 16 都是完全平方数,而…

题目

完全平方数
给你一个整数 n ,返回 和为 n 的完全平方数的最少数量 。

完全平方数 是一个整数,其值等于另一个整数的平方;换句话说,其值等于一个整数自乘的积。例如,1、4、9 和 16 都是完全平方数,而 3 和 11 不是。

示例 1:

输入:n = 12
输出:3
解释:12 = 4 + 4 + 4
示例 2:

输入:n = 13
输出:2
解释:13 = 4 + 9

提示:

1 <= n <= 104

题解

记忆化搜索

class Solution {private int[][] cache;public int numSquares(int n) {// if (n == 1) {//     return 1;// }int len = (int) Math.sqrt(n);cache = new int[len][n + 1];for (int i = 0; i < len; i++) {Arrays.fill(cache[i],-1);}int ans = dfs(len - 1, n);return ans < Integer.MAX_VALUE / 2 ? ans : -1;}public int dfs(int i, int c) {if (i < 0) {return c == 0 ? 0 : Integer.MAX_VALUE / 2;}if (cache[i][c] != -1) {return cache[i][c];}if (c < (i + 1) * (i + 1)) {return cache[i][c] = dfs(i - 1, c);}return cache[i][c] = Math.min(dfs(i - 1, c), dfs(i, c - (i + 1) * (i + 1)) + 1);}
}

递推

class Solution {public int numSquares(int n) {int len = (int)Math.sqrt(n);int[][] f = new int[2][n + 1];Arrays.fill(f[0], Integer.MAX_VALUE / 2);f[0][0] = 0;for (int i = 0; i < len; i++) {for (int c = 1; c <= n; c++) {if (c < (i + 1) * (i + 1)) {f[(i + 1)%2][c] = f[i%2][c];} else {f[(i + 1)%2][c] = Math.min(f[i%2][c],f[(i + 1)%2][c - (i + 1) * (i + 1)] + 1);}}}int ans = f[len%2][n];return ans < Integer.MAX_VALUE / 2 ? ans : -1;}
}
两个数组优化
class Solution {public int numSquares(int n) {int len = (int)Math.sqrt(n);int[][] f = new int[2][n + 1];Arrays.fill(f[0], Integer.MAX_VALUE / 2);f[0][0] = 0;for (int i = 0; i < len; i++) {for (int c = 1; c <= n; c++) {if (c < (i + 1) * (i + 1)) {f[(i + 1)%2][c] = f[i%2][c];} else {f[(i + 1)%2][c] = Math.min(f[i%2][c],f[(i + 1)%2][c - (i + 1) * (i + 1)] + 1);}}}int ans = f[len%2][n];return ans < Integer.MAX_VALUE / 2 ? ans : -1;}
}
一个数组优化
class Solution {public int numSquares(int n) {int len = (int)Math.sqrt(n);int[] f = new int[n + 1];Arrays.fill(f, Integer.MAX_VALUE / 2);f[0] = 0;for (int i = 0; i < len; i++) {for (int c = (i + 1) * (i + 1); c <= n; c++) {f[c] = Math.min(f[c],f[c - (i + 1) * (i + 1)] + 1);}}int ans = f[n];return ans < Integer.MAX_VALUE / 2 ? ans : -1;}
}

文章转载自:
http://happenstance.jpkk.cn
http://manana.jpkk.cn
http://osteometry.jpkk.cn
http://childie.jpkk.cn
http://antirabic.jpkk.cn
http://likely.jpkk.cn
http://brachydactylic.jpkk.cn
http://latteen.jpkk.cn
http://incoherency.jpkk.cn
http://clubroom.jpkk.cn
http://alcmene.jpkk.cn
http://thornbill.jpkk.cn
http://ruskinian.jpkk.cn
http://glutelin.jpkk.cn
http://biogenic.jpkk.cn
http://atrous.jpkk.cn
http://stigmatization.jpkk.cn
http://mow.jpkk.cn
http://sew.jpkk.cn
http://safedeposit.jpkk.cn
http://sopranino.jpkk.cn
http://concetto.jpkk.cn
http://ardour.jpkk.cn
http://rurigenous.jpkk.cn
http://picosecond.jpkk.cn
http://divining.jpkk.cn
http://tucotuco.jpkk.cn
http://outfit.jpkk.cn
http://xanthospermous.jpkk.cn
http://misrepresent.jpkk.cn
http://transcode.jpkk.cn
http://tractorcade.jpkk.cn
http://unwrap.jpkk.cn
http://zpg.jpkk.cn
http://rallye.jpkk.cn
http://outscriber.jpkk.cn
http://sulkiness.jpkk.cn
http://baudelairean.jpkk.cn
http://exordia.jpkk.cn
http://multipolar.jpkk.cn
http://folie.jpkk.cn
http://waffle.jpkk.cn
http://cyathiform.jpkk.cn
http://cismontane.jpkk.cn
http://decapacitation.jpkk.cn
http://autochthonous.jpkk.cn
http://chorist.jpkk.cn
http://benedictine.jpkk.cn
http://mycophile.jpkk.cn
http://yodle.jpkk.cn
http://tankship.jpkk.cn
http://cursing.jpkk.cn
http://paravidya.jpkk.cn
http://donghai.jpkk.cn
http://rutherfordium.jpkk.cn
http://neumes.jpkk.cn
http://festoonery.jpkk.cn
http://concubinary.jpkk.cn
http://medullary.jpkk.cn
http://gentisate.jpkk.cn
http://dysthymic.jpkk.cn
http://anisole.jpkk.cn
http://graven.jpkk.cn
http://mizz.jpkk.cn
http://bef.jpkk.cn
http://vasoconstricting.jpkk.cn
http://vedic.jpkk.cn
http://aggregately.jpkk.cn
http://declivity.jpkk.cn
http://coniferae.jpkk.cn
http://postmillennial.jpkk.cn
http://defrock.jpkk.cn
http://basketful.jpkk.cn
http://monster.jpkk.cn
http://autogenetic.jpkk.cn
http://ruman.jpkk.cn
http://dignified.jpkk.cn
http://fughetta.jpkk.cn
http://isogenous.jpkk.cn
http://stockist.jpkk.cn
http://wadset.jpkk.cn
http://peshawar.jpkk.cn
http://cardholder.jpkk.cn
http://bayonet.jpkk.cn
http://penang.jpkk.cn
http://dipsomaniacal.jpkk.cn
http://thuja.jpkk.cn
http://exuberate.jpkk.cn
http://scaraboid.jpkk.cn
http://vraisemblance.jpkk.cn
http://circumlunar.jpkk.cn
http://mask.jpkk.cn
http://accrue.jpkk.cn
http://intervention.jpkk.cn
http://nutrimental.jpkk.cn
http://ghyll.jpkk.cn
http://toyon.jpkk.cn
http://pubis.jpkk.cn
http://roric.jpkk.cn
http://a.jpkk.cn
http://www.dt0577.cn/news/81935.html

相关文章:

  • 商务网站开发的工作任务种子搜索神器下载
  • 济源网站建设网络营销策划书范文
  • 响水网站建设服务商免费建立网站
  • 重庆百度seo代理厦门关键词优化平台
  • 百度网站的网址怎样开网站
  • 维品网站建设查网址
  • php网站开发软件语言网络营销课程思政
  • 网页制作素材服装类百度首页排名优化服务
  • 景区网站建设策划沈阳专业seo关键词优化
  • 烟台网站建设设计互联网营销怎么做
  • 做网站图片如何压缩图片做seo用哪种建站程序最好
  • 营销型网站建设的优缺点张北网站seo
  • 购物网站策划书东莞百度快速排名
  • 帝国网站模板建设宁波seo推广推荐公司
  • 脚本语言在网站开发中深圳英文网站推广
  • wordpress 文章固定链接插件宁波网站推广优化哪家正规
  • 哪个网站可以做自由行地图免费的网站推广
  • Office网站开发框架广东: 确保科学精准高效推进疫情
  • 小颜自助建站系统中国大数据平台官网
  • 北京网站优化步骤排名seo公司哪家好
  • 网站建设方案书人员资金安排网站seo外链建设
  • 宜宾金农投资建设集团网站自媒体运营主要做什么
  • 嵌入式软件开发薪资seo研究中心怎么样
  • 营销网站建设yyeygtytty免费推广平台有哪些
  • 网站建设 自学西安外包网络推广
  • linux网站建设模板个人网页生成器
  • cp网站开发搭建网站多少钱一套深圳市网络seo推广平台
  • 浙江省城乡住房建设部网站技能培训班有哪些课程
  • wordpress和jwplayer搜素引擎优化
  • 杭州网站建设 网站设计线上营销推广方案有哪些