04 2013 档案

摘要:约瑟夫问题,感谢这篇博客,让我想了两天之后,看了n篇解题报告都没想懂的情况下,彻底搞懂了这个问题blog.csdn.net/tsaid/article/details/7313382#include <iostream> #include <cstdio> using namespace std; int f[15]; int solve(int n,int m) { int i,loc=0; for(i=1;i<=n;i++) { loc=(loc+m-1)%(2*n-i+1); if(loc<n) return 0; } ... 阅读全文
posted @ 2013-04-27 15:07 LJ_COME!!!!! 阅读(111) 评论(0) 推荐(0)
摘要:用的是后缀数组,对于串s1,s2求最长公共子串,最原始的想法就是比较两个串的所有后缀之间的最长公共前缀,可有通过后缀数组优化,先把s1,s2连起来,中间加一个不在s1,s2中的任意一个字符。这样,新形成的串的后缀可以分为两类,一类是包含s1中字符的后缀,一类就是不包含s1中字符的后缀,最后的结果也就是这两类后缀之间的最长公共前缀。额外添加的那个字符的作用就体现于此,这两类后缀的最长公共前缀,也就是s1和s2之间的最长公共前缀,因为这两类后缀的最长公共前缀,肯定在额外添加的那个字符之前就已经匹配结束了,理由显而易。然后接下来就是求这两类后缀的最长公共前缀,只要在得height数组时,比较一下就可 阅读全文
posted @ 2013-04-24 19:15 LJ_COME!!!!! 阅读(136) 评论(0) 推荐(0)
摘要:组合数学,对于长度为l的二进制数n,先求出长度小于l的满足意义的数,这里长度为l的数,都是指二进制以1开头的长度为为l的数,讨论以0开头的数在这种方法下没什么意义,因为每个数都可确定的知道其长度,并且是以1开头的,也就是说这样的分类可以包括所有的数并且没有重叠。然后再求长度为为l的小于n的满足要求的书。然后再检查n看他本身是否满足条件。这样就求出了1~n中满足条件的数的个数,还有c++提交除以2用位运算来实现,不然会wa#include <iostream> #include <cstdio> using namespace std; int f[33][33],re[ 阅读全文
posted @ 2013-04-23 14:26 LJ_COME!!!!! 阅读(114) 评论(0) 推荐(0)
摘要:递推,统计,数位DP水题,但这题在网上归为组合数学,不知道思路#include <iostream> #include <cstdio> #include <cstring> #define LL long long using namespace std; LL f[11][30]; int main() { char s[11]; int i,j,k; for(i=0;i<26;i++) f[0][i]=1; for(i=1;i<10;i++) { for(j=0;j<(26-i);j++) { ... 阅读全文
posted @ 2013-04-20 22:05 LJ_COME!!!!! 阅读(137) 评论(0) 推荐(0)
摘要:1.burnside定理,polya计数法这个大家可以看brudildi的《组合数学》,那本书的这一章写的很详细也很容易理解。最好能完全看懂了,理解了再去做题,不要只记个公式。*简单题:(直接用套公式就可以了)pku2409 Let it Beadhttp://acm.pku.edu.cn/JudgeOnline/problem?id=2409pku2154 Colorhttp://acm.pku.edu.cn/JudgeOnline/problem?id=2154pku1286 Necklace of Beadshttp://acm.pku.edu.cn/JudgeOnline/probl. 阅读全文
posted @ 2013-04-19 21:29 LJ_COME!!!!! 阅读(224) 评论(0) 推荐(0)
摘要:暴力水过,79ms#include <iostream> #include <cstdio> #include <cstring> using namespace std; char tx[10000+10][20]; char s[20]; int len[10000+10],loc[10000+10]; int main() { int i=0; while(scanf("%s",tx[i])) { if(strcmp(tx[i],"#")==0) break; len[i]=strlen(tx[i]); i++; 阅读全文
posted @ 2013-04-18 22:07 LJ_COME!!!!! 阅读(115) 评论(0) 推荐(0)
摘要:KMP的应用如果串s有s(1)循环得到,那么s(1~len-1)一定与s(2~len)匹配,并且len-2+1一定是1的倍数,同理如果由s(1~2),s(1~3)......是一样的道理,但肯定不会这么一个一个枚举,可知可由kmp中的next[]来枚举,减小时间复杂度#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=1000000+10; char s[maxn]; int next[maxn]; void getNext( 阅读全文
posted @ 2013-04-17 21:31 LJ_COME!!!!! 阅读(116) 评论(0) 推荐(0)
摘要:trie的简单应用#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=10000*10+10; int trie[maxn][11]; int val[maxn],tot; char str[10000+10][15]; int Insert(char *s) { int len=strlen(s); int i,u=0,loc; for(i=0;i<len;i++) { loc=s[i]-'0'; .. 阅读全文
posted @ 2013-04-17 17:19 LJ_COME!!!!! 阅读(114) 评论(0) 推荐(0)
摘要:树形DP,f[j][i]表示有j个robot遍历i及其子树并且在此子树返回地球所需的最小值,但还有k个robot遍历子树i及其子树,再返回父亲节点m个机器人这种情况,但是可以证明这种情况一定不会是最优解,所以不予考虑。还有一个地方就是f[0][i]表示用0个robot遍历意思就是说用n个机器人遍历此子树,再返回,可知n=1,道理和前面那种情况的道理一样。在求f[i][j]是用的是分组背包的思想,刚开始多用了一个数组g[][],来实现这个过程,后来看了其他人的代码,想了一想,可以用滚动数组优化,用f[i][j]就可以实现这个过程了#include <iostream> #includ 阅读全文
posted @ 2013-04-16 19:56 LJ_COME!!!!! 阅读(111) 评论(0) 推荐(0)
摘要:状态压缩DP,f[j][i]表示前i行棋子放置状态状态为j的方法数就0<=j<=1<<n,比如j=01010000,表示前i行第5列和第7列放置了棋子的方法总数,具体的递推过程代码如下#include <iostream> #include <cstdio> #include <cstring> using namespace std; int n,k; int num[10],f[1<<8][10],vis[10][10],pa[1<<8]; int main() { while(~scanf("% 阅读全文
posted @ 2013-04-16 14:01 LJ_COME!!!!! 阅读(129) 评论(0) 推荐(0)
摘要:数位DP。假设长度为s的数字,如果是题目中要求的数字时,肯定是每个位置i ,j,1--i非递减,j--s非递增,然后枚举每个点把左右两方相乘,但是想了想,这么简单的统计会造成很多重复,然后再分析,对于i,j无非三种情况i所在位置数字a>j所在位置数字b,a==b,a<b,先算1--s中的每个位置第一种情况的个数的和,然后发现a==b,a<b的所有情况都可化为第一种情况,所以就不用再求这两种情况的数目,因为第一种情况的所有满足题意的数字已经包括了后两种情况满足意一的数字,所以定义状态f[i][j]表示以数字j结尾的长度为i的非递减数字的个数,还有自己感觉数位DP最坑的地方就是细 阅读全文
posted @ 2013-04-10 14:13 LJ_COME!!!!! 阅读(146) 评论(0) 推荐(0)
摘要:KMP简单应用,利用next,一个一个确定是否和后缀匹配#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=400000+10; char s[maxn]; int next[maxn]; int amount[maxn]; int main() { while(~scanf("%s",s)) { int len=strlen(s); int i=0,j=-1; next[0]=-1; ... 阅读全文
posted @ 2013-04-08 21:04 LJ_COME!!!!! 阅读(111) 评论(0) 推荐(0)
摘要:数位DP,各种理解难题#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #define LL long long using namespace std; unsigned long long n; LL f1[25],f2[25],f3[25]; int s[25]; int t; int main() { cin>>t; int i,j,k; f1[0]=0;f2[0]=1;f3[0]=0; for(i=1;i<=19;i++) 阅读全文
posted @ 2013-04-08 13:54 LJ_COME!!!!! 阅读(112) 评论(0) 推荐(0)
摘要:单调队列优化DP//状态转移方程:f[i][j]=min(f[i-k][j-1]+(s[i]-s[i-p])*g[j]) #include <iostream> #include <cstdio> #include <cstring> #define LL long long using namespace std; const LL inf=0x3f3f3f3f3f3f3f3f; LL x[10000+10],s[10000+10],q[10000+10]; LL g[200+10]; LL f[2][10000+10]; int n,k,a,b; int 阅读全文
posted @ 2013-04-06 13:24 LJ_COME!!!!! 阅读(180) 评论(0) 推荐(0)