摘要: #include#include#include#include#include#include#include#include#includeusing namespace std;int main(){ char s1[1010],s2[1010]; while(scanf("%s"... 阅读全文
posted @ 2016-04-02 15:52 Code-dream 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 之前我们介绍过图的邻接矩阵存储法,它的空间和时间复杂度都是N2,现在我来介绍另外一种存储图的方法:邻接表,这样空间和时间复杂度就都是M。对于稀疏图来说,M要远远小于N2。先上数据,如下。4 51 4 94 3 81 2 52 4 61 3 7复制代码 第一行两个整数n m。n表示顶点个... 阅读全文
posted @ 2016-03-31 12:36 Code-dream 阅读(228) 评论(0) 推荐(0) 编辑
摘要: #include #include #include#include using namespace std;struct node{ int a,b; friend bool operator y.a; //如果为 >优先级小的先出队列 反之 }};priority_queu... 阅读全文
posted @ 2016-03-29 12:13 Code-dream 阅读(160) 评论(0) 推荐(0) 编辑
摘要: I Hate ItTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 58191 Accepted Submission(s): 2268... 阅读全文
posted @ 2016-03-25 21:27 Code-dream 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 链接 HDU 1711 Number SequenceKMP 算法 我以自己理解写的,写的不对,不明白的地方海王子出来,一起共同学习;字符串匹配 就是KMP,一般思想,用一个for循环找开头 如果开头一样进入第二个for循环;这样统计 直观 容易理解。但是时间复杂度比较长... 阅读全文
posted @ 2016-03-22 17:53 Code-dream 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 对于这个算法,是求区间里面的最大最小值,一般思想在区间for循环一遍找,但是访问区间次数多的话,且区间长度太长,这样时间复杂度都会太长,我认为就是做了一个预处理使得访问时间大大减短。 怎么才能够得到区间的最值? 所以,如预处理区间的最大值,最小值也是类似的。用一个F二维数组F[ i ][ j ] 表 阅读全文
posted @ 2016-03-22 12:05 Code-dream 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 背包问题九讲 目录 第一讲 01背包问题 第二讲 完全背包问题 第三讲 多重背包问题 第四讲 混合三种背包问题 第五讲 二维费用的背包问题 第六讲 分组的背包问题 第七讲 有依赖的背包问题 第八讲 泛化物品 第九讲 背包问题问法的变化 附录一:USACO中的背包问题 附录二:背包问题的搜索解法 前言 阅读全文
posted @ 2016-03-16 21:05 Code-dream 阅读(16724) 评论(0) 推荐(2) 编辑
摘要: #include#include#include#define NN 2500000using namespace std;typedef long long LL;struct node{ LL l,r,sum,flag;} N[NN];void build(LL l,LL r,LL i)... 阅读全文
posted @ 2016-03-15 15:29 Code-dream 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 1. (1 > 1;// 2 = 21 x = x >> 6;// 64 = 263. 数值转整数加速 10%x = int(1.232) //改为: x = 1.232 >> 0; 4. 交换两个数值(swap),使用 XOR 可以加速20%t = a; a = b; b = t;... 阅读全文
posted @ 2016-03-13 20:37 Code-dream 阅读(325) 评论(0) 推荐(0) 编辑
摘要: int lowbit(int x){ return x&-x;}int add(int pos,int a){ while (pos0) { ans+=c[pos]; pos-=lowbit(pos); } return ans;} 阅读全文
posted @ 2016-03-13 11:19 Code-dream 阅读(150) 评论(0) 推荐(0) 编辑