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
  • 相关阅读:
    Appium
    iOS 定位方式 iOSNsPredicateString 详解
    Appium 遇到 Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 65 的解决方法
    自动化工具 appium 在真机上测试的配置 (使用个人 Apple ID)
    查看iOS App的bundleId
    阿里巴巴热招求推荐求转发
    一文读懂网络协议
    Idea生成Javadoc
    系统监控
    Hystrix使用详解
  • 原文地址:https://www.cnblogs.com/pandy/p/1371472.html
Copyright © 2011-2022 走看看