上一页 1 2 3 4 5 6 7 8 ··· 17 下一页
摘要: 多路归并+优先队列的使用#include <iostream> #include <cstdio> #include <queue> #include <algorithm> using namespace std; const int maxn=2000+10; int a[110][maxn],b[maxn],n,m; struct item { int s,b; item(int s,int b):s(s),b(b) { } }; bool operator < (item a,item b) { return a.s>b.s; 阅读全文
posted @ 2013-05-01 17:31 LJ_COME!!!!! 阅读(193) 评论(0) 推荐(0)
摘要: 约瑟夫问题,感谢这篇博客,让我想了两天之后,看了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!!!!! 阅读(110) 评论(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!!!!! 阅读(223) 评论(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!!!!! 阅读(109) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 17 下一页