上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 99 下一页

2012年8月18日

多米诺骨牌 优化版

摘要: 算法:在之前搜索出状态的基础上,再压缩一次状态。View Code //by yefeng#include<iostream>using namespace std;typedef long long LL; const int mod = 9937;int mask,idx, n , m;struct Matrix{ int mat[257][257]; void zero() { memset(mat,0,sizeof(mat)); } void unit(){ memset(mat,0,sizeof(mat)); fo... 阅读全文

posted @ 2012-08-18 16:38 more think, more gains 阅读(207) 评论(0) 推荐(0) 编辑

HDU 4332 Constructing Chimney 矩阵快速幂

摘要: 算法:1.状态压缩2.搜索3.矩阵快速幂View Code #include<iostream>using namespace std;typedef long long LL;const int mod = 1000000007;const int mask = 255;struct Matrix{ LL mat[100][100]; void unit(){ memset(mat,0,sizeof(mat)); for(int i = 0; i < 100; i++) mat[i][i]=1; } void zero(){... 阅读全文

posted @ 2012-08-18 16:37 more think, more gains 阅读(172) 评论(0) 推荐(0) 编辑

B.寻找最大值

摘要: 算法:1.正向思维如果枚举区间求最值肯定TLE,数据量很大。2.反向思维,枚举每个点的左右区间,虽然两个for循环,我感觉是平均是O(N)的时间复杂度,动态规划的思想,可以求出。3.这题相当诡异,不能给dt数组清空赋值,坑了我一晚上加上午,还不知道为什么。4.我的L[I]记录的是该点能往左到达的边界,R【i]是往右到达的边界。旭他们记录的是以该点向左能扩张的长度,R【i]类似。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#incl 阅读全文

posted @ 2012-08-18 09:38 more think, more gains 阅读(174) 评论(0) 推荐(0) 编辑

2012年8月17日

矩阵乘法 经典题目

摘要: 1。 给定一个有向图,问从A点恰好走k步(允许重复经过边)到达B点的方案数mod p的值把给定的图转为邻接矩阵,即A(i,j)=1当且仅当存在一条边i->j。令C=A*A,那么C(i,j)=ΣA(i,k)*A(k,j),实际上就等于从点i到点j恰好经过2条边的路径数(枚举k为中转点)。类似地,C*A的第i行第j列就表示从i到j经过3条边的路径数。同理,如果要求经过k步的路径数,我们只需要二分求出A^k即可。--摘自,http://www.matrix67.com/blog/archives/276/理解:为什么k步的路径数,我们只需要二分求出A^k?因为每步实际做一次矩阵乘法,矩阵乘法定 阅读全文

posted @ 2012-08-17 11:31 more think, more gains 阅读(336) 评论(0) 推荐(0) 编辑

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 ··· 4 5 6 7 8 9 10 11 12 ··· 99 下一页

导航