不同主分区的数量 [英] Number of distinct prime partitions

查看:233
本文介绍了不同主分区的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

一个数字,因为它是素数部分

我有这个家庭作业分配我的,硬地狱,我必须得到所有的明确的分区的给定数字。例如,数字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.

这篇关于不同主分区的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆