题目:http://community.topcoder.com/stat?c=problem_statement&pm=13204&rd=15857 这道题目须要用到博弈论中的经典理论,Sprague–Grundy theorem,以下将相关理论做一个总结: Impartial Game:公平游戏,两方除了谁先開始游戏外,其余都同样. Nim:一类经典的Impartial Game,非常多游戏都能够等价于Nim. Nimber(Grundy numbers):能够理解为标识一个游戏状态的…
称号:http://community.topcoder.com/stat? c=problem_statement&pm=13143&rd=15853 參考:http://apps.topcoder.com/wiki/display/tc/SRM+620 又是一道关于概率的题目,考虑dp方法.关键是找准突破口,将题目条件的"至少有一个大于4的连通图"转换为"全部连通图都小于等于3". 代码: #include <algorithm> #…
题意: 给1*n的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢.问先手必胜还是必败. 分析: 求状态的grundy值(也就是sg值),详细怎么求详见代码.为什么这么求要自己想的,仅仅可意会(别人都说去看game theory,呵呵). 代码: //poj 3537 //sep9 #include <iostream> #include <set> using namespace std; int grundy[2048]; int h[2048]; int get_grundy(…
从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可 int minimum(int M, vector <int> heights) { sort(heights.begin(),heights.end()); int minFloor = 10000; for(int i = heights.size()-1; i >=M-1; -- i){ int floor = 0; for(int j = 0; j < M; ++j) floor +=heights[i]-he…
排个序,求前k个元素和即可 int minimum(int K, vector <int> danceCost) { sort(danceCost.begin(),danceCost.end()); return accumulate(danceCost.begin(),danceCost.begin()+K,0); }…
几乎相同的一标题.欲了解更多请参阅:http://community.topcoder.com/stat?c=problem_statement&pm=13211&rd=15857 思维: 1 序列 2 大厦的当前数量的计算i时候,全部可能的最小建筑物改动数 3 每次计算i+1的时候.全部可能的最小建筑物改动数 4 同一时候能够比較得到i+1的时候最小改动数 得到的程序也不复杂 #include <vector> #include <algorithm> #incl…
题目:http://community.topcoder.com/stat? c=problem_statement&pm=10409&rd=15854 利用高斯消元求线性空间的基,也就是求矩阵的秩. 代码: #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <iostream> #include &l…
题目:http://community.topcoder.com/stat?c=problem_statement&pm=10554&rd=15855 符合条件的集中非1的元素个数是非常少的,能够用回溯加剪枝.实际执行速度非常快. 代码: #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <iostream&…
SRM 623 DIV2 1000pt 题意:给出一个最多50*50的矩阵,每个单元可能为'.'.'P'.'A','.'代表空地,你每次操作可以把一个P或者A拿到空地上,求一个最大的含有相同字符的矩形面积,最多K次操作. 首先用一个数组预处理出所有矩形所包含这三种字符的数量,然后枚举每一个矩形,如果只含有相同字符,那么这个面积是可以取到的. 如果含有多种字符,枚举含哪种字符时所需操作最少,大矩阵内如果含有一个及以上空地并且这个矩形的面积是小于等于你当前枚举的字符的数量,操作数=矩形内空地数+令一…
选修了人工智能课程,老师布置了调研任务:Grundy,开始看了一些资料并没有看懂. 后来找到了一篇文,写的很棒,里面有好多博弈相关的问题与分析,分享出来给大家: http://endless.logdown.com/posts/2014/05/05/find-out-the-winning-strategies-of-the-game-nim-and-grundy-number-notes 这个服务器可能是外国的?打开的很慢,不要认为自己的网炸了...哈哈哈 下面就贴一点自己为了做海报(Grun…