poj-3791-An Easy Game-记忆化搜索】的更多相关文章

Function Run Fun Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17843   Accepted: 9112 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…
题目链接:http://poj.org/problem?id=3249 思路:dp[i]表示到点i的最大收益,初始化为-inf,然后从入度为0点开始bfs就可以了,一开始一直TLE,然后优化了好久才4000ms险过. 之后有写了个dfs记忆化搜索,果然快多了. bfs AC code: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<q…
题目链接:http://poj.org/problem?id=1661 一道还可以的记忆化搜索题,主要是要想到如何设dp,记忆化搜索是避免递归过程中的重复求值,所以要得到dp必须知道如何递归 由于这是个可以左右移动的所以递归过程肯定设计左右所以dp的一维为从左边下或者从右边下,而且和层数有关所以另一维为层数 于是便可以得到dp[count][flag],flag=1表示count层从左边下要多久,flag=0表示count层从右边下要多久.然后就是dfs的递归 过程 #include <iost…
思路:总共有18条边,9个三角形. 极大极小化搜索+剪枝比较慢,所以用记忆化搜索!! 用state存放当前的加边后的状态,并判断是否构成三角形,找出最优解. 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #d…
滑雪 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个 区域中最长底滑坡.区域由一个二维数组给出.数组的每个数字代表点的高度.下面是一个例子 1 2 3 4 5 16 17 18 19…
第一眼看是线段交集问题,感觉不会= =.然后发现n是1000,那好像可以n^2建图再做.一想到这里,突然醒悟,直接记忆化搜索就好了啊..太蠢了.. 代码如下: #include <stdio.h> #include <algorithm> #include <string.h> using namespace std; + ; int n,m,r; struct node { int l,r,val; void read() {scanf("%d%d%d&qu…
典型的记忆化搜索问题,dfs一遍即可.但是不知道WA在哪里了= =,一直都没找出错误.因为思路是很简单的,肯定是哪里写挫了,因此不再继续追究了. WA的代码如下,希望日后有一天能找出错误= =: ————————————————灵光一闪的分界线—————————————————— 在写博客的时候突然灵光一闪,想到了错在哪里了= =.总的来说还是考虑问题不周导致的.AC代码如下: #include <stdio.h> #include <algorithm> #include <…
题目:http://poj.org/problem?id=1191 黑书116页的例题 将方差公式化简之后就是 每一块和的平方 相加/n , 减去平均值的平方. 可以看出来 方差只与 每一块的和的平方有关,所以就是求每个矩形的总分的平方和 尽量小.... #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #inc…
题目链接:http://poj.org/problem?id=1579 思路分析:题目给出递归公式,使用动态规划的记忆搜索即可解决. 代码如下: #include <stdio.h> #include <string.h> + ; int dp[MAX_N][MAX_N][MAX_N]; int w( int a, int b, int c ) { ) return dp[a][b][c]; || b <= || c <= ) ; else if ( a < b…
题目大意:给你一个8*8的棋盘,上面有四个棋子,给你一个初始排布,一个目标排布,每次移动,可以把一个棋子移动到一个相邻的空位,或者跨过1个相邻的棋子,在保证棋子移动不超过8次的情况下,问能否把棋盘上的棋子由初始排布变成目标排布 8*8的棋盘,刚好不爆ull,状压那些位置有棋子 然后从初始状态开始,暴搜出当前状态下,移动一个棋子之后所有可能到达的状态 直接搜,总状态数是8^8,此外还有常数,会爆 由于给定了目标排布,考虑meet in middle 从起始状态和目标状态各搜4步即可 为了防止爆栈,…
一道简单但是题意蛋疼的题目 题意:给你个n*n的图,开始在左上角,要求走到右下角有多种走法,图上的数表示走几步,只能向右或向下走. #include<iostream> #include<cstdio> using namespace std; #define N 40 char map[N][N]; int n; __int64 dp[N][N]; __int64 solve(int x,int y) { if(dp[x][y]) return dp[x][y]; if(x==n…
You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or right end of the array but cannot take from both…
题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16150   Accepted: 5768 Description 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘.(每次切割都只能沿着棋盘格子的边进行) 原棋盘上每一格…
题目传送门:http://poj.org/problem?id=1579 Function Run Fun Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20560   Accepted: 10325 Description We all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c): if a <=…
滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑坡.区域由一个二维数组给出.数组的每个数字代表点的高度.下面是一个例子 1 2 3 4 5 16 17…
Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 8990   Accepted: 2004 Description Mr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's hard to have a job…
http://poj.org/problem?id=3186   Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time…
题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5535   Accepted: 2500 Description An n x n game board is populated with integers, one nonnegative integer per square. The goal is to tr…
http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了,说正事~ 题目大意: 中文题吖,就不用我说了哈哈~~~~~~做中文题真舒服,不用开词典^ ^ 思路: 搜索的时候显然会有重复的所以采用记忆化搜索. 顺带用了下宏定义,让代码简洁点. #include<cstdio> #include<cstring> #include<algo…
题意:给出一个二维矩阵,要求从其中的一点出发,并且当前点的值总是比下一点的值大,求最长路径 记忆化搜索,首先将d数组初始化为0,该点能够到达的路径长度保存在d数组中,同时把因为路径是非负的,所以如果已经计算过某个点,那么这个点的d一定是正的,所以每次搜的时候判断一下d[i][j],如果是正的,就不用再计算了. #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #inc…
题意:略 直接用记忆化搜索就行了 #include<cstdio> #include<iostream> using namespace std; int n,m; int map[105][105]; int len[105][105]={0}; int dp(int x,int y) { int max,temp; if(len[x][y]) return len[x][y]; max=0; if(x+1<n&&map[x][y]>map[x+1][…
Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14210   Accepted: 9432 Description The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard…
http://acm.fzu.edu.cn/problem.php?pid=1005 Description The fastfood chain McBurger owns several restaurants along a highway. Recently, they have decided to build several depots along the highway, each one located at a restaurant and supplying several…
滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 88560   Accepted: 33212 Description Michael 喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个 区域中最长底滑坡.区域由一个二维数组给出.数组的每个数字代表点的高度.下面是一个例子 1 2 3 4 5 16 1…
从任意一点可以往上下左右比它小的数那里走,问最远长度是多少 *解法:每一点dfs搜索一遍 记忆化搜索:http://blog.csdn.net/acmer_sly/article/details/53440798 递归:求解的方法都是相同的(距离是周围的点最大值加一),假设已知周围点的距离则dd[i] = dfs(xx, yy) + 1;  每一次递归将当前状态入栈,递归到头的时候返回时取出栈中状态 #include <iostream> #include <cstdio> usi…
(我是不会告诉你我是抄的http://www.cnblogs.com/scau20110726/archive/2013/02/27/2936050.html这个人的) 一开始没有想到要化一下方差的式子 怎么搞都挂-- 尴尬 /* 题目固定是8*8,本来想用点的坐标来表示矩形的,但是发现用标号来表示会方便一点 对于最小的小方格,用(i,j)表示,即第i行第j列的小方格,注意不是点的坐标 所以对于一个矩形,我们用它左上角的小方格和右下角的小方格来表示 例如,整个棋盘就是(1,1),(8,8) 另外…
一,题意: 中文题 二.分析: 主要利用压缩dp与记忆化搜索思想 三,代码: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> using namespace std; const int Big=20000000; int Mat[10][10]; int N; int sum[10][10]; int…
题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位dp,由于一个二进制数的最高位必须为1.所以设置变量first记录前面位是否有1,若有1,则可随意放,否则,仅仅可放1. 同一时候.上面的推断决定了搜索时len的大小与二进制本身的长度不一定相等,所以需两个变量对1和0的个数进行记录. 用dp[a][b][c]保存长度a,b个0,c个1的数字个数.记忆化搜索.…
Triangle War Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2685   Accepted: 1061 Description Triangle War is a two-player game played on the following triangular grid:  Two players, A and B, take turns filling in any dotted line connec…
话说DP=记忆化搜索这句话真不是虚的. 面对这道题目,题意很简单,但是DP的时候,方向分为四个,这个时候用递推就好难写了,你很难得到当前状态的前一个真实状态,这个时候记忆化搜索就派上用场啦! 通过对四个方向进行搜索,即可得到当前状态的最优解. #include <iostream> #include <cstdio> using namespace std; ][]; ][]; ]= {{,},{,-},{,},{-,}}; int r,c; int dpac(int i,int…