上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页
摘要: 最近发现以前的东西都忘得差不多了,在这里刷刷水题并查集: 1 int find_parent(int x) 2 { 3 return x = p[x] ? x : p[x] = find_parent(p[x]); 4 } 5 6 void merg(int a,int b) 7 { 8 int x = find_parent(a); 9 int y = find_parent(b);10 if(x != y)11 {12 p[x] = y;13 }14 } 1 #include 2 #include 3 #include 4 ... 阅读全文
posted @ 2013-07-21 19:12 再见~雨泉 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 母函数介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数) 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 using namespace std;12 #define MAX(a,b) (a > b ? a : b)13 #define MIN(a,b) (a #include#include#include#include#include#include#inclu 阅读全文
posted @ 2013-07-19 23:57 再见~雨泉 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 母函数的简单应用http://acm.hdu.edu.cn/showproblem.php?pid=2079介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数) 1 #include 2 3 4 5 int main() 6 { 7 int T; 8 while(~scanf("%d", &T))while(T--) 9 {10 int c1[41]={0},c2[41]={0};11 int num,val;12 int i,n,k;13 scanf("... 阅读全文
posted @ 2013-07-19 23:52 再见~雨泉 阅读(1139) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1028母函数:例1:若有1克、2克、3克、4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案?如何解决这个问题呢?考虑构造母函数。如果用x的指数表示称出的重量,则: 1个1克的砝码可以用函数1+x表示, 1个2克的砝码可以用函数1+x2表示, 1个3克的砝码可以用函数1+x3表示, 1个4克的砝码可以用函数1+x4表示,(1+x)(1+x2)(1+x3)(1+x4)=(1+x+x2+x3)(1+x3+x4+x7)=1+x+x2+2x3+2x4+2x5+2x6+2x7+x8+x9+x10 从上面的函数知道. 阅读全文
posted @ 2013-07-19 23:45 再见~雨泉 阅读(2605) 评论(1) 推荐(1) 编辑
摘要: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define MAX(a,b) (a) > (b)? (a):(b)10 #define MIN(a,b) (a) 0)x%=(b/g);39 else x=x%(b/g)+(b/g);40 printf("%I64d\n",x);41 }42 return 0;43 } 阅读全文
posted @ 2013-07-17 23:43 再见~雨泉 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 对钉子DP,如果钉子存在DP[i+1][j]+=DP[i][j]; DP[i+1][j+1]+=DP[i][j]; 如果不存在DP[i+2][j+1]+=4*DP[i][j];见代码:(有一个比较坑爹的就是要用__Int64) 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define MAX(a,b) (a) > (b)? (a):(b)10 #define MIN(a,b) (a) < (b)? (... 阅读全文
posted @ 2013-07-10 11:00 再见~雨泉 阅读(337) 评论(0) 推荐(0) 编辑
摘要: PolygonTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 4456Accepted: 1856DescriptionPolygon is a game for one player that starts on a polygon with N vertices, like the one in Figure 1, where N=4. Each vertex is labelled with an integer and each edge is labelled with either the symbol + (add 阅读全文
posted @ 2013-07-06 22:03 再见~雨泉 阅读(1609) 评论(0) 推荐(0) 编辑
摘要: 题目大意就是帮你给N条字符串,每条长度不超过20。问要将他们单一识别出来,每个字符串最短可以缩为多短。如:abcabcdefgbcadef这四个字符串就可分别缩写为abcabcdbad方法: 字典树(可以参阅http://s.acmore.net/show_article/show/58)。另外我还用了一个bool数组last用来记录每个单一识别的字符串最短可以到哪个位置,他的下标就是字典树中每个字母对应的序号方法如下:(以上面的为例)当输入的字符串在某一个位置开始与之前的不同,就记录这个不同的字母(设置为true),之后的不再改变当输入字符串的某位置在建好的树中时,把last加长(设置为tr 阅读全文
posted @ 2013-07-06 18:51 再见~雨泉 阅读(264) 评论(0) 推荐(0) 编辑
摘要: F个花,V个花瓶,对应F*V种值,后面的花只能选择前面的花所在花瓶的后面的花瓶,求最大值的总和。 1 #include 2 #include 3 #include 4 #include 5 #define MAX(a,b) (a) > (b)? (a):(b) 6 #define MIN(a,b) (a) < (b)? (a):(b) 7 #define mem(a) memset(a,0,sizeof(a)) 8 #define INF 1000000007 9 #define MAXN 10510 using namespace std;11 12 int DP[MAXN][M 阅读全文
posted @ 2013-07-06 15:30 再见~雨泉 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 参考http://s.acmore.net/show_article/show/58以附上代码 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #... 阅读全文
posted @ 2013-06-19 21:43 再见~雨泉 阅读(224) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2203题目意思很简单,求s1串所构成的环中是否有s2这个串用CMP参考http://s.acmore.net/show_article/show/44 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <stack> 6 #include <set> 7 #include <queue> 阅读全文
posted @ 2013-06-19 21:40 再见~雨泉 阅读(252) 评论(0) 推荐(0) 编辑
摘要: 题目大意就是说给你一个长度为N的区间,并给定区间每个点的值,求Q次询问区间<x,y>之间的最大值与最小值的差这是我第一道用线段树做的题目^_^采用线段树记录区间x,y的最大值用最小值,每一次询问的复杂度就是logN总复杂度就是QlogN,详见代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define MAX(a,b) (a)>(b)?(a):(b) 5 #define MIN(a,b) (a)<(b)?(a):(b) 6 #define M 阅读全文
posted @ 2013-06-12 01:24 再见~雨泉 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 今天上POJ水了几道最简单的DP,却似乎没有一道是依次AC的,相当郁闷。都是因为审题不清,的注意这个问题了!!!!首先是1157,很简单的DP从左往右有V个花瓶,上往下有F个花,吧F中花放进V个花瓶里面,下面的花必须放在上面的花的右边,每一种搭配方式有一个欣赏值,求这个值的和的最大值。很简单,就直接用DP[i][j]表示到i,j时候的最大欣赏值 DP[i][j]=MAX(DP[i][j-1],DP[i][j]+DP[i-1][j-1]);但我却忽略了可能都为负数的情况,所以不能全部直接memset(0);DP[i][0]=-INF这样才对!!! 1 #in... 阅读全文
posted @ 2013-06-06 00:52 再见~雨泉 阅读(390) 评论(0) 推荐(0) 编辑
摘要: Floyd算法摘自:百度百科:http://baike.baidu.com/view/14495.htm百科名片弗洛伊德算法Floyd算法又称为弗洛伊德算法,插点法,是一种用于寻找给定的加权图中顶点间最短路径的算法。该算法名称以创始人之一、1978年图灵奖获得者、斯坦福大学计算机科学系教授罗伯特·弗洛伊德命名。核心思路通过一个图的权值矩阵求出它的每两点间的最短路径矩阵。从图的带权邻接矩阵A=[a(i,j)] n×n开始,递归地进行n次更新,即由矩阵D(0)=A,按一个公式,构造出矩阵D(1);又用同样地公式由D(1)构造出D(2);……;最后又用同样的公式由D(n-1)构造 阅读全文
posted @ 2013-06-05 16:41 再见~雨泉 阅读(731) 评论(0) 推荐(0) 编辑
摘要: kruskal算法摘自:百度百科http://baike.baidu.com/view/247951.htm百科名片K r u s k a l算法每次选择n- 1条边,所使用的贪婪准则是:从剩下的边中选择一条不会产生环路的 具有最小耗费的边加入已选择的边的集合中。注意到所选取的边若产生环路则不可能形成一棵生成树。K r u s k a l算法分e 步,其中e 是网络中边的数目。按耗费递增的顺序来考虑这e 条边,每次考虑一条边。当考虑某条边时,若将其加入到已选边的集合中会出现环路,则将其抛弃,否则,将它选入。Kruskal算法算法定义克鲁斯卡尔算法假设 WN=(V,{E}) 是一个含有 n 个顶 阅读全文
posted @ 2013-06-05 16:39 再见~雨泉 阅读(897) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页