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 ...
随机推荐
- centos7下配置mysql5.7.24主从复制
前置条件 准备两台服务器(可以是虚拟机),系统为centos7 此处演示的两台服务器:192.168.8.134.192.168.8.135 第一步:安装mysql5.7.24 先在两台服务器上安装m ...
- ssl证书生成方法
一般情况下,如果能找到可用的证书,就可以直接使用,只不过会因证书的某些信息不正确或与部署证书的主机不匹配而导致浏览器提示证书无效,但这并不影响使用. 需要手工生成证书的情况有: 找不到可用的证书 需要 ...
- 数组与集合List的相互转化
数组转化为集合 #此运用的是Arrays中的asList方法,返回一个List集合 *当数组元素为基本数据类型是把整个数组当作一个元素放入List集合中,代码举例: ,,}; List<int[ ...
- TED_Topic3:The hidden reason for poverty the world needs to address now
The hidden reason for poverty the world needs to address now By Gary Haugen # Background about our s ...
- maven使用过程中遇到的问题总汇
1:web.xml is missing and <failOnMissingWebXml> is set to true 造成原因: 使用maven创建项目时有时在pom.xml的war ...
- 51Nod - 1006 最长公共子序列Lcs模板
给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). 比如两个串为: abcicba abdkscab ab是两个串的子序列,abc也是,abca也是,其中abca是这 ...
- css3全屏背景显示
background:url(zhongyi2.png) no-repeat center center fixed;/* -webkit-background-size:cover; -moz-ba ...
- HDU 1034 Candy Sharing Game (模拟)
题目链接 Problem Description A number of students sit in a circle facing their teacher in the center. Ea ...
- N-gram语言模型与马尔科夫假设关系(转)
1.从独立性假设到联合概率链朴素贝叶斯中使用的独立性假设为 P(x1,x2,x3,...,xn)=P(x1)P(x2)P(x3)...P(xn) 去掉独立性假设,有下面这个恒等式,即联合概率链规则 P ...
- perl6正则 4: before / after 代码断言: <?{}> / <!{}>
<?before> <? befor XXX> 某字符在 xxx 之前 <?after > <?after XXX> 某字符之后有XXX 对应的取反分别 ...