原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795题意:给出广告板的高和宽,然后在给出1*m的广告,判断每块广告牌是否能放开,原则是广告尽量往广告牌的左上角放。源码:#include<iostream>using namespace std;#define lson l,mid,index<<1#define rson mid+1,r,index<<1|1#define MAX 222222int node[MAX<<2];int h,w,num;void build(int l,int r,i Read More
posted @ 2013-03-30 15:47 supersnow0622 Views(122) Comments(0) Diggs(0)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754(区间最大值)源码:#include<iostream>using namespace std;#define lson l,mid,index<<1#define rson mid+1,r,index<<1|1#define max 200000int score[max<<2];char ch;void getMax(int index){ score[index]=score[index<<1]>score[index&l Read More
posted @ 2013-03-30 15:35 supersnow0622 Views(131) Comments(0) Diggs(0)
最近一个周在学习线段树,晒晒学习成果。线段树结构:以最大区间是10为例 1【1 , 10】 / \ 2【1,5】 3【6,10】 / \ / \ 4【1,3】 5【4,5】 6【6,8】 7【9,10】 / \ / \ / \ / \ 8【1,2】9【3,3】10【4,4】11【5,5】 12【6,7】13【8,8】14【9,9】15【10,10】 / \... Read More
posted @ 2013-03-30 15:31 supersnow0622 Views(130) Comments(0) Diggs(0)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1297 解题分析:按照最后一个人的性别分析,他要么是男,要么是女,所以可以分两大类讨论: 1、如果n个人的合法队列的最后一个人是男,则对前面n-1个人的队列没有任何限制,他只要站在最后即可,所以,这种情况一共有F(n-1);2、如果n个人的合法队列的最后一个人是女,则要求队列的第n-1个人务必也是女生,这就是说,限定了最后两个人必须都是女生,这又可以分两种情况: 2.1、如果队列的前n-2个人是合法的队列,则显然后面再加两个女生,也一定是合法的,这种情况有F(n-2); 2.2、但是,难点在于... Read More
posted @ 2013-03-25 21:09 supersnow0622 Views(194) Comments(0) Diggs(0)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2045 解题分析:假设n个方格有f(n)种涂法,n-1个方格有f(n-1)种涂法。分两种情况:1、前n-1个合法,则第1个、第n-1个还有第n个颜色都不一样。这时有f(n-1)种涂法;2、前n-1个不合法,则第1个和第n-1个颜色不同,也就是前n-2个合法,有f(n-2)种涂法,第n个有2种涂法。所以这种情况下有f(n-2)*2种涂法。所以f(n)=f(n-1)+2*f(n-2)源代码如下:#include<iostream>using namespace std;int main(){ Read More
posted @ 2013-03-25 14:55 supersnow0622 Views(124) Comments(0) Diggs(0)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1465 解题分析:信 : A B C D E F G......信封:a b c d e f g......假设n封信全放错有f(n)种可能,则n-1封信全放错有f(n-1)种可能如果A信放错了,有n-1种可能,1、假如A错放入b中,而B也错放入a中,则剩下的n-2个放错有f(n-2)种可能,所以这种情况有(n-1)*f(n-2)种可能; 2、假如A错放入b中,而B没有放入a中,则剩下的包含B在内的n-1封信放错有f(n-1)种可能,所以这种情况有(n-1)*f(n-1)种可能。所以f(n)=(n. Read More
posted @ 2013-03-25 14:41 supersnow0622 Views(107) Comments(0) Diggs(0)
原题链接:http://www.cnblogs.com/supersnow622/admin/EditPosts.aspx?opt=1 解题分析:设第n个位置时有f(n)种放置的方法,则第n-1个位置时有f(n-1)种放置的方法。当放入第n个位置时,要考虑两种情况:1、第n个位置的砖竖着放,则前n-1块砖放得正好填满,有f(n-1)种放法2、第n个位置的砖横着放,则前n-2块砖放得正好填满,有f(n-2)种放法所以f(n)=f(n-1)+f(n-2)代码如下:#include<iostream>using namespace std;int main(){ _int64 arr[5 Read More
posted @ 2013-03-25 14:21 supersnow0622 Views(146) Comments(0) Diggs(0)
(1) n条直线最多分平面问题 题目大致如:n条直线,最多可以把平面分为多少个区域。 析:可能你以前就见过这题目,这充其量是一道初中的思考题。但一个类型的题目还是从简单的入手,才容易发现规律。当有n-1条直线时,平面最多被分成了f(n-1)个区域。则第n条直线要是切成的区域数最多,就必须与每条直线相交且不能有同一交点。这样就会得到n-1个交点。这些交点将第n条直线分为2条射线和n-2条线断。而每条射线和线断将以有的区域一分为二。这样就多出了2+(n-2)个区域。 故:f(n)=f(n-1)+n =f(n-2)+(n-... Read More
posted @ 2013-03-18 16:23 supersnow0622 Views(209) Comments(0) Diggs(0)
杭电1010 Tempter of the Bone 原题连接http://acm.hdu.edu.cn/showproblem.php?pid=1010代码如下: #include <iostream> using namespace std; char map[8][8]; int r, c, ttime, x2, y2; //ttime 是所给时间T,【r:行、c:列】 bool flag; //x2、y2是终点坐标 int x... Read More
posted @ 2013-03-11 11:50 supersnow0622 Views(123) Comments(0) Diggs(0)
回溯法其实也是一种搜索算法,它可以方便的搜索解空间。回溯法解题通常可以从以下三步入手: 1、针对问题,定义解空间 2、确定易于搜索的解空间结构 3、以深度优先的方式搜索解空间,并在搜索的过程中进行剪枝 回溯法通常在解空间树上进行搜索,而解空间树通常有子集树和排列树。 针对这两个问题,算法的框架基本如下: 用回溯法搜索子集合树的一般框架: void backtrack(int t){ if(t > n) output(x); else{ for(int i = f(n,t); i <= g(n,t);i++){ x... Read More
posted @ 2013-03-10 20:33 supersnow0622 Views(217) Comments(0) Diggs(0)