Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 查找是否为';It’用一些给定的数字组成一个整数是可能的_Algorithm_Dynamic Programming_Greedy - Fatal编程技术网

Algorithm 查找是否为';It’用一些给定的数字组成一个整数是可能的

Algorithm 查找是否为';It’用一些给定的数字组成一个整数是可能的,algorithm,dynamic-programming,greedy,Algorithm,Dynamic Programming,Greedy,问题: 找出是否可以用21、19和37组成一个整数(比如N) a. N will be provided as input b. You can use only these three numbers: 27,19,37 c. Only multiplication, addition, repetition and replacement are allowed 例如: Input: 24, Output: not possible Input: 94, Output: possible

问题:

找出是否可以用21、19和37组成一个整数(比如N)

a. N will be provided as input
b. You can use only these three numbers: 27,19,37
c. Only multiplication, addition, repetition and replacement are allowed
例如:

Input: 24, Output: not possible
Input: 94, Output: possible - 94 = 19*3 + 37
我的问题是:

  • 在这个作业中,你能帮我显示DP/Div和Con/Greedy的路径吗
  • 我应该选择哪一个,为什么不选择其他的(在这种情况下)
  • 如果您能更灵活地用DP/Greedy/Div&Con方程进行解释,并解释您的思维过程,我将不胜感激。
    例如,在最长公共子序列中,我们使用以下内容:

    //assuming X[i.....m] and Y[j.....n]    
    LCS(i,j) = {
        0 ,                                 when  i = m or j=n
        Max { LCS(i, j+1) , LCS(i+1, j)  }  when X[i] ≠ Y[j]  
        1+ LCS(i+1,j+1)                     when X[i] == Y[j]
    }
    

  • 与背包问题相同,参数如下:-

    W = Knapsack capacity = N
    
    items = 19 ( N/19 times), 27 (N/27 times), 37 (N/37 times).
    
    Cost & weight of items are same.
    
    Maximize profit. If maximum profit equals N then it is possible to construct N using 19,27,37
    
    背包问题有一个DP解:-


    注意:你应该自己研究背包问题,不要再为背包的代码发帖了。

    我不明白这个问题<代码>19+19-37=1。您可以重复该模式来生成所需的每个数字(
    N=2*N*19-N*37
    )。你能把允许的运算明确化吗?@Heuster减法似乎是不允许的(我不确定这里的“重复”和“替换”是什么意思)。谢谢Vikram,喜欢它…也在等待其他不同的思维过程:)@ArnabDutta另一种方法是线性整数规划,其中19*x+27*y+37*z=N,x,y,z>=0。可以使用标准解算器求解。但在任何情况下,你都会得到类似的时间复杂度,因为问题是NP完全问题(第二个想法是……)