POJ 1597 Function Run Fun
记忆化搜索。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<iostream>
using namespace std; struct X{
int x,y,z;
X(int xx,int yy,int zz)
{
x=xx;
y=yy;
z=zz;
}
bool operator < (const X &a) const {
if(x!=a.x) return x>a.x;
if(y!=a.y) return y>a.y;
return z>a.z;
}
};
int a,b,c;
map<X,bool>f;
map<X,int>w; int work(int x,int y,int z)
{
if(f[X(x,y,z)]) return w[X(x,y,z)]; f[X(x,y,z)]=true;
if(x <= || y <= || z <= ) w[X(x,y,z)]=;
else if(x > || y > || z > ) w[X(x,y,z)] = work(,,);
else if(a < b && b < c) w[X(x,y,z)] =work(x, y, z-) + work(x, y-, z-) - work(x, y-, z);
else w[X(x,y,z)] = work(x-, y, z) + work(x-, y-, z) + work(x-, y, z-) - work(x-, y-, z-); return w[X(x,y,z)];
} int main()
{
while(~scanf("%d%d%d",&a,&b,&c))
{
if(a==-&&b==-&&c==-) break;
printf("w(%d, %d, %d) = %d\n",a,b,c,work(a,b,c));
} return ;
}
POJ 1597 Function Run Fun的更多相关文章
- POJ 1579 Function Run Fun 【记忆化搜索入门】
题目传送门:http://poj.org/problem?id=1579 Function Run Fun Time Limit: 1000MS Memory Limit: 10000K Tota ...
- poj 1579 Function Run Fun(记忆化搜索+dp)
题目链接:http://poj.org/problem?id=1579 思路分析:题目给出递归公式,使用动态规划的记忆搜索即可解决. 代码如下: #include <stdio.h> #i ...
- POJ 1579 Function Run Fun
简单动态规划,详细代码网上有!
- poj 1579 Function Run Fun 【记忆化递归】
<题目链接> 题目大意: 给出一些递归式,直接套用这些递归式计算. 解题分析: 递归式已经由题目明确说明了,但是无脑递归铁定超时,所以此时,我们需要加上记忆化,对于那些已经算过的,就没有必 ...
- POJ 1579 Function Run Fun 记忆化递归
典型的记忆化递归问题. 这类问题的记忆主要是利用数组记忆.那么已经计算过的值就能够直接返回.不须要进一步递归了. 注意:下标越界.递归顺序不能错,及时推断是否已经计算过值了,不要多递归. 或者直接使用 ...
- 洛谷P1464 Function HDU P1579 Function Run Fun
洛谷P1464 Function HDU P1579 Function Run Fun 题目描述 对于一个递归函数w(a,b,c) 如果a≤0 or b≤0 or c≤0就返回值11. 如果a> ...
- hdu 1331 Function Run Fun
Problem Description We all love recursion! Don't we? Consider a three-parameter recursive function w ...
- HDU 1331 Function Run Fun(记忆化搜索)
Problem Description We all love recursion! Don't we? Consider a three-parameter recursive function w ...
- POJ1579:Function Run Fun
Description We all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c ...
随机推荐
- numpy数组中冒号和负号的含义
numpy数组中":"和"-"的意义 觉得有用的话,欢迎一起讨论相互学习~Follow Me 在实际使用numpy时,我们常常会使用numpy数组的-1维度和& ...
- JNI实现JAVA和C++互相调用
SDK.h #ifndef SDK_H #define SDK_H #include "AsyncProxy.h" #include "Module.h" #i ...
- codevs 2796 最小完全图
2796 最小完全图 http://codevs.cn/problem/2796/ 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 若一个图的每一对不 ...
- HDU 6211 卡常数取模 预处理 数论
求所有不超过1e9的 primitive Pythagorean triple中第2大的数取模$2^k$作为下标,对应a[i]数组的和. 先上WIKI:https://en.wikipedia.org ...
- c# WebService SOAP及Rest调用
SOAP及Rest的调用区别参照如下: REST似乎在一夜间兴起了,这可能引起一些争议,反对者可以说REST是WEB诞生之始甚而是HTTP出现之日就相伴而生的原则.但是毋庸置疑的事实是,在Google ...
- 去除UITableView多余的seperator
UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [tableView setTableFooterView:v]; [v release] ...
- canvas 绘制星座图(好玩)--转载
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- ActiveMQ笔记之点对点队列(Point-to-Point)
1. 点对点通信 点对点是一种一对一通信方式,更像是有一个队列,一个人往队列里放消息,另一个人从队列中取消息,其最大的特点是一个消息只会被消费一次,即使有多个消费者同时消费,他们消费的也是不同的消息. ...
- 初学Memcached安装及使用【转】
1.yum install memcached安装memecached 2.chkconfig memcached on设置memcached开机启动 3.service memcached star ...
- 斐讯路由器L(联)B(壁)K-码兑换包安全下车通道(图文教程)
大家好,最近大家比较关心的斐讯路由器如何下车问题,楼主亲自试提取了一遍,记录下过程,欢迎大家一起讨论. 言归正传,上图,上图! No.1 打开斐讯提供的良心k码退换通道: https://tech-s ...