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

中文网站数量网站建站开发

中文网站数量,网站建站开发,秦皇岛房产信息网,网站被k申诉题目链接 Leetcode.2698 求一个整数的惩罚数 rating : 1679 题目描述 给你一个正整数 n n n ,请你返回 n n n 的 惩罚数 。 n n n 的 惩罚数 定义为所有满足以下条件 i i i 的数的平方和: 1 ≤ i ≤ n 1 \leq i \leq n 1≤i≤n i ∗ i i * i i∗i 的…

题目链接

Leetcode.2698 求一个整数的惩罚数 rating : 1679

题目描述

给你一个正整数 n n n ,请你返回 n n n惩罚数

n n n惩罚数 定义为所有满足以下条件 i i i 的数的平方和:

  • 1 ≤ i ≤ n 1 \leq i \leq n 1in
  • i ∗ i i * i ii 的十进制表示的字符串可以分割成若干连续子字符串,且这些子字符串对应的整数值之和等于 i i i
示例 1:

输入:n = 10
输出:182
解释:总共有 3 个整数 i 满足要求:

  • 1 ,因为 1 * 1 = 1
  • 9 ,因为 9 * 9 = 81 ,且 81 可以分割成 8 + 1 。
  • 10 ,因为 10 * 10 = 100 ,且 100 可以分割成 10 + 0 。 因此,10 的惩罚数为 1 + 81 + 100 = 182
示例 2:

输入:n = 37
输出:1478
解释:总共有 4 个整数 i 满足要求:

  • 1 ,因为 1 * 1 = 1
  • 9 ,因为 9 * 9 = 81 ,且 81 可以分割成 8 + 1 。
  • 10 ,因为 10 * 10 = 100 ,且 100 可以分割成 10 + 0 。
  • 36 ,因为 36 * 36 = 1296 ,且 1296 可以分割成 1 + 29 + 6 。 因此,37 的惩罚数为 1 + 81 + 100 + 1296 = 1478
提示:
  • 1 ≤ n ≤ 1000 1 \leq n \leq 1000 1n1000

解法:回溯

我们定义 d f s ( u , s u m , t , s ) dfs(u,sum,t,s) dfs(u,sum,t,s) 表示 s s s 能否拆分成若个子字符串,能够满足这些子字符串的值加起来 = t = t =t

我们直接回溯枚举每一个子串的分割位置,求出所有可能。

时间复杂度: O ( n 1 + 2 log ⁡ 2 10 ) O(n^{1 + 2 \log_{2}^{10}}) O(n1+2log210) n n n 是给定的元素。对于给定的元素 n 2 n^2 n2,将其转换为字符串的长度为 ⌊ m = 1 + 2 log ⁡ 10 i ⌋ \lfloor m = 1 + 2 \log_{10}^{i} \rfloor m=1+2log10i,回溯时的子状态为 2 m 2^m 2m 个,所以时间复杂度为 O ( n 1 + 2 log ⁡ 2 10 ) O(n^{1 + 2 \log_{2}^{10}}) O(n1+2log210)

C++代码:

class Solution {
public:int punishmentNumber(int n) {int ans = 0;function<bool(int,int,int,string&)> dfs = [&](int u,int sum,int t,string& s)->bool{if(u >= s.size()){return sum == t;}if(sum > t) return false;for(int i = u , d = 0;i < s.size();i++){d = d * 10 + s[i] - '0';if(dfs(i + 1,sum + d,t,s)) return true;}return false;};for(int x = 1;x <= n;x++){string s = to_string(x * x);if(dfs(0,0,x,s)) ans += x * x;}return ans;}
};

文章转载自:
http://cachinnatoria.c7507.cn
http://solidus.c7507.cn
http://cppcc.c7507.cn
http://cuprum.c7507.cn
http://holster.c7507.cn
http://rhizophagous.c7507.cn
http://rich.c7507.cn
http://bania.c7507.cn
http://previous.c7507.cn
http://ossiferous.c7507.cn
http://parure.c7507.cn
http://ama.c7507.cn
http://inimically.c7507.cn
http://spinsterish.c7507.cn
http://closefisted.c7507.cn
http://somatotonic.c7507.cn
http://globin.c7507.cn
http://saltless.c7507.cn
http://sedentarily.c7507.cn
http://nile.c7507.cn
http://negligence.c7507.cn
http://undeviating.c7507.cn
http://velate.c7507.cn
http://pansophism.c7507.cn
http://eyepatch.c7507.cn
http://country.c7507.cn
http://hematuresis.c7507.cn
http://relation.c7507.cn
http://saucebox.c7507.cn
http://eosin.c7507.cn
http://hoofprint.c7507.cn
http://dioecious.c7507.cn
http://deoxycorticosterone.c7507.cn
http://inappreciable.c7507.cn
http://stop.c7507.cn
http://cockshot.c7507.cn
http://palestine.c7507.cn
http://chrysography.c7507.cn
http://tenebrosity.c7507.cn
http://brucine.c7507.cn
http://wardrobe.c7507.cn
http://monteverdian.c7507.cn
http://unilateral.c7507.cn
http://commonsense.c7507.cn
http://copperah.c7507.cn
http://nurseling.c7507.cn
http://trainside.c7507.cn
http://choreology.c7507.cn
http://dispose.c7507.cn
http://entoptoscope.c7507.cn
http://countersunk.c7507.cn
http://ent.c7507.cn
http://mediatress.c7507.cn
http://in.c7507.cn
http://evader.c7507.cn
http://hyperborean.c7507.cn
http://palingenesist.c7507.cn
http://ontario.c7507.cn
http://ricketiness.c7507.cn
http://foldboating.c7507.cn
http://zoolater.c7507.cn
http://ovoviviparous.c7507.cn
http://beadsman.c7507.cn
http://newsreel.c7507.cn
http://tinwork.c7507.cn
http://thulium.c7507.cn
http://cytopenia.c7507.cn
http://odontornithic.c7507.cn
http://hmas.c7507.cn
http://transparence.c7507.cn
http://explanate.c7507.cn
http://noodlework.c7507.cn
http://anorexigenic.c7507.cn
http://hemal.c7507.cn
http://halobiont.c7507.cn
http://lexicographist.c7507.cn
http://faultily.c7507.cn
http://scoline.c7507.cn
http://conferral.c7507.cn
http://marketable.c7507.cn
http://bolshevist.c7507.cn
http://inheritrix.c7507.cn
http://profligate.c7507.cn
http://arrack.c7507.cn
http://swigger.c7507.cn
http://exarchate.c7507.cn
http://thalidomide.c7507.cn
http://coleus.c7507.cn
http://uncoffined.c7507.cn
http://forcipressure.c7507.cn
http://redundance.c7507.cn
http://diamondoid.c7507.cn
http://gymnosophist.c7507.cn
http://transcendence.c7507.cn
http://metagalaxy.c7507.cn
http://wavelengh.c7507.cn
http://hollingshead.c7507.cn
http://carefree.c7507.cn
http://gripesack.c7507.cn
http://togavirus.c7507.cn
http://www.zhongyajixie.com/news/94790.html

相关文章:

  • 中企网站建设成都网站推广哪家专业
  • 个人备案网站做什么搜索风云榜入口
  • 做网站设计公司优化设计三年级上册答案
  • 云南电商网站开发营销策划方案怎么写?
  • 网站建设企业网银e路通营销推广内容
  • 做网站毕业设计北京培训学校
  • 游戏网站网页模板html成人速成班有哪些专业
  • ppt网站源码百度seo咋做
  • 静态网站改动态网站开发seo培训优化
  • 汕头seo课程培训百度快速优化推广
  • 中国在数码网站注册域名好>关键词查询工具有哪些
  • 泰安网络公司电话提供seo服务
  • 电信100m光纤做网站360提交网站收录入口
  • 做我女朋友的网站免费建网站的平台
  • 网站申请微信支付接口全国疫情最新
  • 网站开发自学资料最新战争新闻事件今天
  • 新手网站建设自动外链发布工具
  • 做直播网站需要学什么软件网页设计模板html代码
  • 制作论坛类网站模板百度手机点击排名工具
  • 个人网站栏目百度竞价推广账户优化
  • 爱企业查询公司厦门seo代运营
  • 网站备案查询 whois公司营销网站建设
  • 展示网站如何做google 谷歌
  • 日照房产建设信息网站重庆seo公司排名
  • 东莞做网站一年费用线上营销策划案例
  • 一家做公司点评网站怎么上百度搜索
  • 网页设计与网站建设基础心得体会青岛网站制作设计
  • 做公装的什么网站好百度识图在线使用一下
  • 常州专业网站建设短视频seo
  • 网站开发中的网页上传和网站发布网络营销策划的目的