博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nefuoj 16 Function Run Fun
阅读量:4205 次
发布时间:2019-05-26

本文共 1556 字,大约阅读时间需要 5 分钟。

Function Run Fun

Problem:16

Time Limit:1000ms

Memory Limit:65536K

Description

We all love recursion! Don't we? 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) This is an easy function to implement. The problem is, if implemented directly, for moderate values of a, b and c (for example, a = 15, b = 15, c = 15), the program takes hours to run because of the massive recursion.

Input

The input for your program will be a series of integer triples, one per line, until the end-of-file flag of -1 -1 -1. Using the above technique, you are to calculate w(a, b, c) efficiently and print the result.

Output

Print the value for w(a,b,c) for each triple.

Sample Input

1 1 12 2 210 4 650 50 50-1 7 18-1 -1 -1

Sample Output

w(1, 1, 1) = 2w(2, 2, 2) = 4w(10, 4, 6) = 523w(50, 50, 50) = 1048576w(-1, 7, 18) = 1

Hint

dp

Source

pku #include 
#include
using namespace std;long long data[50][50][50];long long inf(int x,int y,int z){ if(x<=0||y<=0||z<=0) return 1; if(x>20||y>20||z>20) return inf(20,20,20); if(x
>x>>y>>z) { if(x==-1&&y==-1&&z==-1) break; memset(data,-1,sizeof(data)); cout<<"w("<
<<", "<
<<", "<
<<")"<<" = "<
<

转载地址:http://ecali.baihongyu.com/

你可能感兴趣的文章
Mybatis 解决字段名与实体类属性名不相同的冲突
查看>>
Mybatis Generator最完整配置详解
查看>>
Mybatis 一级缓存和二级缓存
查看>>
Hibernate 出现Unsupported major.minor version 52.0 [duplicate]
查看>>
Hibernate 使用Intellij IDEA自动生成.hbm.xml文件
查看>>
Hibernate 出现org.hibernate.MappingNotFoundException: resource:**.hbm.xml not found问题的解决方案
查看>>
Hibernate 注解使用总结
查看>>
JAVA 事务之JDBC事务、JTA事务和容器事务
查看>>
EJB 是什么
查看>>
Hibernate 异常StrategySelectionException: Unable to resolve name EhCacheRegionFactory
查看>>
Hibernate 异常CacheException: Another unnamed CacheManager already exists in the same VM
查看>>
Python 常用的几种安装Module方式
查看>>
Mongodb 创建用户后登陆出现mongoAuthentication failed
查看>>
Mongodb GridFS、服务器脚本和数据库引用
查看>>
Mongodb 数据库管理
查看>>
JAVA 基本类型的默认值和取值范围
查看>>
JDK 1.5-1.8特性
查看>>
Jsp 出现异常IllegalArgumentException:Control character in cookie value or attribute解决方法
查看>>
Servlet 使用字符流读取文件乱码解决方法
查看>>
设计模式 Concurrency 之 ReadWriteLock 读写锁
查看>>