摘要: /* 尼姆博奕(Nimm Game):有三堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜。 这种情况最有意思,它与二进制有密切关系,我们用(a,b,c)表示某种局势,首先(0,0,0)显然是奇异局势,无论谁面对奇异局势,都必然失败。第二 种奇异局势是(0,n,n),只要与对手拿走一样多的物品,最后都将导致(0,0,0)。仔细分析一下,(1,2,3)也是奇异局势,无论对手如何拿,接下来都可 以变为(0,n,n)的情形。 计算机算法里面有一种叫做按位模2加,也叫做异或的运算,我们用符号(+)表示这种运算。这种运算和一般加法不同的一点... 阅读全文
posted @ 2013-05-14 21:08 Roly Yu 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hit.edu.cn/hoj/problem/view?id=1402整数划分问题Submitted: 886,Accepted: 374整数划分是一个经典的问题。希望这道题会对你的组合数学的解题能力有所帮助。Input每组输入是两个整数n和k。(1 <= n <= 50, 1 <= k <= n)Output对于每组输入,请输出六行。第一行: 将n划分成若干正整数之和的划分数。第二行: 将n划分成k个正整数之和的划分数。第三行: 将n划分成最大数不超过k的划分数。第四行: 将n划分成若干奇正整数之和的划分数。第五行: 将n划分成若干不同整数 阅读全文
posted @ 2013-05-14 20:08 Roly Yu 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=3374最小表示法:http://tobyaa.blog.163.com/blog/static/30248591201261604349913/#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1000005;char str[maxn];int next[maxn];void ge 阅读全文
posted @ 2013-05-14 18:36 Roly Yu 阅读(214) 评论(0) 推荐(0) 编辑
摘要: /* 对于小数据用这dfs,大数据就用递推的思想。*/#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <queue>#include <map>#include <stack>#include <vector>using namespace std ;const int maxn = 20 阅读全文
posted @ 2013-05-14 15:13 Roly Yu 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 题目:http://codeforces.com/contest/304/problem/B#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <algorithm>#include <math.h>#include <fstream>#include <vector>#include <map>#include <queue>#include <stack& 阅读全文
posted @ 2013-05-14 09:11 Roly Yu 阅读(186) 评论(0) 推荐(0) 编辑