摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4359很明显dp,先预处理。需要用到排列组合,然后可以用递推的方法求出来。中间需要再加一个数组f来标记,不然会超时。dp[i][k]表示i个数组成深度为k的树的总数f[i][k]表示 i个数组成深度不超过k的树的总数dp[i][k]=左子树深度为k-1&&右子树的深度小于等于k-1 + 左子树深度小于k-1&&右子树的深度等于k-1View Code 1 # include<stdio.h> 2 # include<string.h> 3 # 阅读全文
posted @ 2012-08-14 16:37 奋斗青春 阅读(352) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4328用dp求图中包含的最大矩阵的问题。此题可以看着是hdu 1505 City Game 的加强版View Code 1 # include<stdio.h> 2 # include<string.h> 3 # include<stdlib.h> 4 # define N 1005 5 char map[N][N]; 6 int uR[N],uB[N],OB[N],OR[N],l[N],r[N]; 7 /* 8 uR[j]表示第j个字符上面有多少个R 9 uB[ 阅读全文
posted @ 2012-08-14 09:54 奋斗青春 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4332先用状态压缩求出相邻两层之间的关系,然后用矩阵的快速幂来求每一层有8个位置然后就有256种状态,但是可以发现,有4个是对称的,也就只用计算70种状态。我没优化,直接用256种状态进行的计算,如果一直按矩阵的快速幂来求总是栈溢出,必须要先预处理矩阵的1-30次幂的值。View Code 1 # include<stdio.h> 2 # include<string.h> 3 # include<stdlib.h> 4 # define Mod 10000000 阅读全文
posted @ 2012-08-14 08:36 奋斗青春 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4339线段树或者 树状数组+二分记录两个字符串在该区间内有多少个字符相匹配。线段树:View Code 1 # include<stdio.h> 2 # include<string.h> 3 # include<stdlib.h> 4 # define N 1000005 5 char s1[N],s2[N]; 6 struct node{ 7 int l,r; 8 int num; 9 }tree[4*N]; 10 void bulid(int l,int 阅读全文
posted @ 2012-08-14 08:25 奋斗青春 阅读(306) 评论(0) 推荐(0) 编辑