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
  • 相关阅读:
    MySql日期与时间函数
    Redis内存分析工具redis-rdb-tools
    MYSQL5.7脚本运行时出现[Warning] Using a password on the command line interface can be insecure
    Prometheus
    Shopt命令(删除排除)
    Nginx配置跨域支持功能
    Nginx之 try_files 指令
    Grafana使用阿里云短信的报警实现
    用python发送短消息(基于阿里云平台)
    同步pod时区与node主机保持一致
  • 原文地址:https://www.cnblogs.com/pandy/p/1371472.html
Copyright © 2011-2022 走看看