zoukankan      html  css  js  c++  java
  • pku1579Function Run Fun动态规划题:递归函数(会TLE)

    题目大意:

    Consider a three-parameter recursive function w(a, b, c):

    if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns:
    1

    if a > 20 or b > 20 or c > 20, then w(a, b, c) returns:
    w(20, 20, 20)

    if a < b and b < c, then w(a, b, c) returns:
    w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c)

    otherwise it returns:
    w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1)

    如果直接用递归函数肯定会tle,到目前为止碰到两种解决方案:

    1)先用暴力法列出数值表,找规律,或用数学方法推导,直接找到递推式。

    2)在程序开始先算出所有题目要求的数值范围,并保存,在主程序里直接调用就行了。(对于某些递归不适用)。

    愚见。。。。。。有时候我自己都表达不清楚,以后发现错误了再修改咯。

    这样一来,题目就很简单了。用题目所给的递推式事先算好所有值。

    代码如下:

     

    Code
  • 相关阅读:
    阿里十八罗汉、腾讯五虎将、百度七剑客……大佬们是如何找到创始合伙人的?
    子元素margin-top后,跟父元素一起下沉
    css 学习网址
    文字折行不折行 css
    js typeof
    position_css
    springmvc initial初始化
    android MD5 SHA1
    hibernate 三种状态
    Springmvc Exception
  • 原文地址:https://www.cnblogs.com/pandy/p/1371472.html
Copyright © 2011-2022 走看看