2012年8月16日

矩阵一维递推 菲波拉契数

摘要: 算法:利用矩阵乘法求解递推,时间复杂度O(lgn)View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using namespace std;#define MAXN 10#defin 阅读全文

posted @ 2012-08-16 21:28 more think, more gains 阅读(206) 评论(0) 推荐(0) 编辑

矩阵乘法

摘要: 1.定义:(来自百度)基本定义 它是这样定义的,只有当矩阵A的列数与矩阵B的行数相等时A×B才有意义。一个m×n的矩阵a(m,n)左乘一个n×p的矩阵b(n,p),会得到一个m×p的矩阵c(m,p),满足 矩阵乘法满足结合律,但不满足交换律 一般的矩乘要结合快速幂才有效果。(基本上所有矩阵乘法都要用到快速幂的) 在数学中,一个矩阵说穿了就是一个二维数组。一个n行m列的矩阵可以乘以一个m行p列的矩阵,得到的结果是一个n行p列的矩阵,其中的第i行第j列位置上的数等于前一个矩阵第i行上的m个数与后一个矩阵第j列上的m个数对应相乘后所有m个乘积的和。比如,下面的 阅读全文

posted @ 2012-08-16 19:52 more think, more gains 阅读(309) 评论(0) 推荐(0) 编辑

Teamwork Brings Profits! 搜索枚举

摘要: 算法:搜索枚举,注意FOR循环初始值。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using namespace std;int mp[20][20];int hash[20] 阅读全文

posted @ 2012-08-16 19:32 more think, more gains 阅读(161) 评论(0) 推荐(0) 编辑

1005 container

摘要: 对一种数据结构有两种操作:1.是插入元素2.输出中位数,并且删除之。数据结构题,splay水过。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;//节点定义typedef struct node{ node *child[2], *pf; int v, size;}*Node;Node root = NULL;void update( Node p ){ if( p == NULL) 阅读全文

posted @ 2012-08-16 19:23 more think, more gains 阅读(164) 评论(0) 推荐(0) 编辑

1003 线段树树状数组区间覆盖

摘要: 算法:比赛时是对线段长度从大到小排序,一次插入查询。一直WA。赛后证明这种算法是错误的。比如1 6 5 7 6 10这组数据就无法通过。正确的算法应该是对线段的x从小到大排序,Y从大到小排序。用线段树或树状数组维护区间和都可。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<map>#include<iostream>#include<algorithm>#include<vector>using namespace 阅读全文

posted @ 2012-08-16 19:21 more think, more gains 阅读(315) 评论(0) 推荐(0) 编辑

导航