上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 25 下一页
摘要: 题目链接:http://poj.org/problem?id=3974 Manacher算法效率真不错,用后缀数组A的都沙茶了。。 1 //STATUS:C++_AC_235MS_10904KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vec 阅读全文
posted @ 2013-04-10 14:42 zhsl 阅读(268) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4513 当时比赛没有A掉的题目,在Manacher匹配的时候维护有序就可以了。 1 //STATUS:C++_AC_156MS_2212KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm& 阅读全文
posted @ 2013-04-10 14:39 zhsl 阅读(551) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 直接用Manacher算法解决即可,先构造字符串,例如 abc -> $#a#b#c# ,第一个‘$’是为了防止溢出字符串。其实也可以不构造字符串,直接去Manacher,具体做法是,当 i 为奇数时为‘#’,为偶数时再去比较。 1 //STATUS:C++_AC_281MS_1348KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math. 阅读全文
posted @ 2013-04-10 14:37 zhsl 阅读(364) 评论(0) 推荐(0) 编辑
摘要: 转送门:http://blog.csdn.net/ggggiqnypgjg/article/details/6645824 这里,我介绍一下O(n)回文串处理的一种方法。Manacher算法.原文地址:http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-longest-palindrome-sub-string/ 其实原文说得是比较清楚的,只是英文的,我这里写一份中文的吧。 首先:大家都知道什么叫回文串吧,这个算法要解决的就是一个字符串中最长的回文子串有多长。这个... 阅读全文
posted @ 2013-04-10 14:31 zhsl 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1699 太爽了这题,1AC。容易想到用状态压缩DP来做,f[k][i][j]表示当前 i 状态有 k 个串并且串以 j 结尾的最短串。则 f[k][i][rt]=Min{ f[k][i][rt] , f[k][st][r]+len[j]+g[r][j] }。其中状态 i 用位运算表示所包含的具体的串,1010表示包含串2和4。这里要注意转移方程中的rt,要考虑串包含的情况。 1 //STATUS:C++_AC_0MS_324KB 2 #include<stdio.h> 3 #include<stdlib.h> 阅读全文
posted @ 2013-04-10 00:34 zhsl 阅读(512) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003 状态转移方程还是很好想的:f[i][j]表示第 i 个节点放 j 个机器人的最优解,f[i][j]=Min{ f[i][j] , f[i][j-k] + f[v][k] + (k?k:2)*e[i].w } 。 写这个树形DP的时候,暴露了我以前没有仔细考虑的问题,导致状态转移的时候删删改改了很久。、 1.仔细考虑转移方程初始化的问题,要根据求Min或者Max以及容量是否恰好来确定。 2.在分组背包转移时,f[i][j]是前几组的最优值。 1 //STATUS:C++_AC_25... 阅读全文
posted @ 2013-04-09 21:18 zhsl 阅读(398) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=3070 矩阵乘法优化,水题一枚。 1 //STATUS:C++_AC_132MS_0KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vector>10 #include< 阅读全文
posted @ 2013-04-09 21:09 zhsl 阅读(295) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1674 看到题目就想到:ans=n-循环节个数。 1 //STATUS:C++_AC_32MS_212KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vector>10 #i 阅读全文
posted @ 2013-04-09 00:46 zhsl 阅读(455) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1707 利用bernoulli方程来解决此题。 数学上,伯努利数Bn的第一次发现是与下述数列和的公式有关: 其中n为固定的任意正整数。 这数列和的公式必定是变量为m,次数为n+1的多项式,称为伯努利多项式。伯努利多项式的系数与伯努利数有密切关系如下: 举例说,把n取为1,我们有 伯努利数可以由下列递推公式计算: ,初值条件为B0= 1。 [摘自wikipedia] 注意:这里计算的是0~m-1的值,因此最后第二项还要加上一个m^n; 1 //STATUS:C++_AC_0MS_140KB 2 #i... 阅读全文
posted @ 2013-04-08 23:25 zhsl 阅读(602) 评论(0) 推荐(0) 编辑
摘要: 摘自:http://www.cnblogs.com/jackiesteed/articles/2198534.html想深究的童鞋可以看看这本书:)-->100个著名初等数学问题历史和解.pdf第01题,阿基米德分牛问题.太阳神有一牛群,由白,黑,花,棕四种颜色的公,母牛组成.在公牛中,白牛数多于棕牛数,多出之数相当于黑牛数的1/2+1/3;黑牛数多于棕牛数,多出之数相当于花牛数的1/4+1/5;花牛数多于棕牛数,多出之数相当于白牛数的1/6+1/7.在母牛中,白牛数是全体黑牛数的1/3+1/4;黑牛数是全体花牛数1/4+1/5;花牛数是全体棕牛数的1/5+1/6;棕牛数是全体白牛数的1 阅读全文
posted @ 2013-04-08 19:21 zhsl 阅读(551) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1286 有旋转和轴对称两种基本置换,先考虑旋转的情况,当旋转 i 个珠子的时候,可以得出循环节有gcd(n,i)个,则和为 Σ 3^gcd(n,i)。轴对称的情况很容易考虑,分n为奇数和偶数就可以了,n为奇数: n*3^((n+1)/2) n为偶数:n/2*(3^(n/2)+3^(n/2+1))。 1 //STATUS:C++_AC_0MS_132KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include 阅读全文
posted @ 2013-04-08 17:17 zhsl 阅读(347) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=3270 把数列循环分解,注意到长度为k的循环最少用k-1次置换,那么次循环的最优值就是用循环中的最小值去与每个置换,还要考虑此循环中的最优值可以由其它循环影响,影响的那个循环肯定还有数列中的最小值。 1 //STATUS:C++_AC_16MS_396KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #incl 阅读全文
posted @ 2013-04-08 00:50 zhsl 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1026 简单的置换题目,求出置换群后直接取余即可。 1 //STATUS:C++_AC_32MS_308KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vector>10 # 阅读全文
posted @ 2013-04-07 21:55 zhsl 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1964 空白区域之间有权值,求经过所有空白区域的哈密顿回路的最小权值。简单的插头DP,空白区域特殊处理即可。 1 //STATUS:C++_AC_203MS_664KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include 阅读全文
posted @ 2013-04-07 13:02 zhsl 阅读(295) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.fzu.edu.cn/problem.php?pid=1977 题目(备份):View Code Problem DescriptionThe pollution of the earth is so serious that people can not survive any more. Fortunately, people have found a new planet that maybe has life, and we call it "Pandora Planet".Leonardo Da Vinci is the only 阅读全文
posted @ 2013-04-03 17:51 zhsl 阅读(435) 评论(0) 推荐(0) 编辑
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 25 下一页