100-动态规划
蒝味
这个作者很懒,什么都没留下…
展开
-
dfs bfs模版
DFS:/*该DFS框架以2D坐标范围为例,来体现DFS算法的实现思想。*/#include#include#includeusing namespace std;const int maxn=100;bool vst[maxn][maxn]; // 访问标记int map[maxn][maxn]; // 坐标范围int dir原创 2012-11-24 23:22:19 · 486 阅读 · 0 评论 -
整数划分
求n表示成1到n 有几种和的表示方法例如:4 = 4 4 = 3 + 1 4 = 2 + 2 4 = 2 + 1 + 1 4 = 1 + 1 + 1 + 1用m表示划分成几个数相加那么:根据n和m的关系,考虑以下几种情况:(1) 当n=1时,不论m的值为多少(m>0),只有一种划原创 2013-08-07 21:28:26 · 690 阅读 · 0 评论 -
poj 1014 - 多重背包
关键词: 01背包,多重背包的二进制拆分#include #include #include #include #define MAX 300010using namespace std;int num[MAX];int cou,sum;void add(int k, int value) { //多重背包的二进制拆分 for(int i = 0; ; i++原创 2013-08-04 15:43:32 · 631 阅读 · 0 评论 -
poj-3628-Bookshelf 2
题目意思:有个书架,高度为H,现在FJ有N个奶牛,每个奶牛有个高度hi,现在将奶牛堆起来,使得堆起来的高度大于等于H,现在要求最小高度差。B - Bookshelf 2Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status Prac原创 2013-05-11 09:19:08 · 895 阅读 · 0 评论 -
hdu 4165(卡特兰数列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4165题目解析:这题是卡特兰数列。具体的看百度百科里面有解释。 题意:在一个瓶子里有N片药,每次吃半片,从瓶子里可能拿出整片,也可能拿出半片,如果拿出整片,记为W,半片记为H。问有多少种排列。用两个状态写的时候这个题就很水了 容易的出状态方程:dp[原创 2012-11-24 10:13:48 · 1143 阅读 · 0 评论 -
dfs(深度优先搜素)poj1088
题目链接:http://poj.org/problem?id=1088题目解析:要求出最长的降序子序列,遍历四个方向记忆化搜索; #include#include#includeusing namespace std;int dp[101][101],a[101][101];int n,i,j,k,m;int dfs(int x,int y){ if(原创 2012-09-17 21:25:17 · 625 阅读 · 0 评论 -
hdu 1203(出国留学得offer的概率)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1203题目解析:至少得到一份offer的概率计算:1-没被录取的概率:1-(1-a)*(1-b);#include#include#include#include#include#include#include#include#includeusing names原创 2012-10-27 14:15:51 · 1340 阅读 · 0 评论 -
hdu 1176(天上掉馅饼了)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176题目解析:记得以前做比赛的时候就有这个题目,不过当时连题目都还看不懂,现在来看的话,题目是看懂了。但是用到的知识点有不明白了。不管怎么样,都是在一次次跌倒后爬起来的,所以不要灰心。这代题目是dp题,大神们归之为数塔的变形,后来看了代码,果然如此; 用i来原创 2012-11-22 23:49:10 · 673 阅读 · 0 评论 -
poj 3639(兑换美元)
题意:初始有加拿大的$1000,给出每天一个美国美元与加拿大美元的兑换率,每次兑换需要花费3%的手续费,并且还会把小于美分的给省去,问最后最多有多少加拿大美元。题解:dp[i][0]为第i天最多有多少加拿大美元,dp[i][1]为第i天最多有多少美国美元,dp[i][0]=max(dp[i-1][0],update(dp[i-1][1]*per*0.97));dp[i][1]=max(原创 2012-12-07 14:17:38 · 721 阅读 · 0 评论 -
UVA 784(dfs填充房间)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=725题目意思:给定一个房间,房间四周都是封闭的,但是房间里面会有相通的门,开始里面有个点,要求从这个点开始能够填到的地方全部标记为#,包括自己,输出填充后的房间地图代码:input2XXX原创 2012-11-03 20:06:50 · 669 阅读 · 0 评论 -
poj 3984迷宫问题
题目链接:http://poj.org/problem?id=3984题目解析:这题算是搜索里面的简单题了吧,题目也很好理解,就是找到最短的路径出去,并输出0所在的位置;想说的是,暴力搜索的时候,注意边界,我做到现在所有的dfs,bfs,都要在固定范围内进行搜索。然后是进行逐个的搜索,其实也不难理解的。具体的看看代码,自己多理解一点吧!!! 本题用的是结构体做的bfs。之所以用结构体,是因原创 2012-11-08 18:15:34 · 5013 阅读 · 0 评论 -
UVA 572(简单的dfs)
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits.GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the原创 2012-11-03 19:37:26 · 2811 阅读 · 1 评论 -
poj 1321棋盘问题
题目链接:http://poj.org/problem?id=1321题目解析:人都傻了,没看清题目就想开始做了。结果浪费了好多时间TATn表示的是棋盘的行数和列数,而用“.”表示棋盘空白的区域,而“#”表示棋盘区域,也就是棋子能摆放的位置,k表示要放的棋子数,因此总的来说,这个算是dfs里面的水题了、代码:#include#include#include#includ原创 2012-11-09 20:21:58 · 682 阅读 · 0 评论 -
codefores-335B-求最长的回文序列
B. Palindrometime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a string s, determine if it contains an原创 2013-08-09 09:45:57 · 1084 阅读 · 0 评论