不同主分区的数量

编程入门 行业动态 更新时间:2024-10-14 06:18:06
本文介绍了不同主分区的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 一个数字,因为它是素数部分

我有这个家庭作业分配我的,硬地狱,我必须得到所有的明确的分区的给定数字。例如,数字7具有五个不同的素数分区(或五种不同的方式来表示其具有的2个素数分区):

I have this homework assignment of mine, hard as hell, where I have to get all the distinct prime partitions of a given number. For example, number 7 has five different prime partitions (or five different ways of representing the 2 prime partitions it has):

  • 5 + 2
  • 2 + 5
  • 3 + 2 + 2
  • 2 + 3 + 2
  • 2 + 2 + 3
  • 5 + 2
  • 2 + 5
  • 3 + 2 + 2
  • 2 + 3 + 2
  • 2 + 2 + 3

如您所见,主要。我不必打印所有不同的分区,只有它们的数量。

As you can see, the number itself is excluded in the case it's a prime. I don't have to print all the distinct partitions, only the number of them.

所以我有点失去了这一点。我完全无法生成任何代码,但我认为我应该从动态编程的角度来看待这一点。我只是要求一些提示。有没有人有一个想法?提前感谢。

So I'm a bit lost with this. I've been completely unable to produce any code, but I think I should approach this from a dynamic programming kind of view. I'm only asking for some hints. Has anyone got an idea? Thanks in advance.

输入的最大数字为100. 此外,程序的运行时间不能超过1秒,内存限制为128 MB 。

The highest inputted number is 100. Also, the running time of the program cannot exceed 1 second, and the memory limit is 128 MB.

推荐答案

要解决这个问题,您需要结合三个想法:

To solve this one you are going to need to combine three ideas:

说明给定的数字是n:

  • 找到小于n的所有素数,如下所示此处。

从你的素数组和n。几个提示是此处和此处

dynamically calculate the subset sum from your prime array and n. A few hints are here and here

然后,计算每个答案的不同排列数从第二步,作为此处。

then, calculate the number of distinct permutations of each answer you get from step two, as here.

当然,这只是一个提示。但它应该帮助你大量烹饪你的最终代码。

Now of course, this is just a hint. But it should help you a great deal to cook up your final code.

更多推荐

不同主分区的数量

本文发布于:2023-11-24 13:21:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分区   数量

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!