摘要:My first reaction was, total No. of strings - no. of palindromic strings. But looks like counting all palindromic strings is not that easy.. So it has...
阅读全文
04 2015 档案
摘要:Please note input constraints. String length will not exceed 100, which means, we can use relatively naive representation\calculation for anagrams: so...
阅读全文
摘要:Sieve of Eratosthenesclass Solution {public: int countPrimes(int n) { if(n rec(n + 1, false); int bound = floor(sqrt(n)); i...
阅读全文
摘要:Simplied a DFS\BFS with minor modification.#include #include #include #include #include #include using namespace std;typedef vector> Matrix;typedef pa...
阅读全文
摘要:Typical tree recursion works. The key is: ANY node can be treated as the root, since it is about edge, not about node. This simplifies things a lot.#i...
阅读全文
摘要:This is a super interesting bit problem. This link can be found in discussion panel:http://math.stackexchange.com/questions/712487/finding-xor-of-all-...
阅读全文
摘要:Intuitive coding problem. But several details to take care.#include #include #include #include #include #include #include using namespace std;bool pla...
阅读全文
摘要:Typical greedy\recursion algorithm.#include #include #include #include #include #include using namespace std;struct Node{ Node() : pinx(0), nodeCnt...
阅读全文
摘要:Really interesting problem! My 1st solution was DP based, like bottom-up pattern, but it got TLE since it is O(n^2). Then I thought there must be a O(...
阅读全文
摘要:Just picture the shifting process in your mind..class Solution {public: int rangeBitwiseAnd(int m, int n) { if (m == n) return m; int...
阅读全文
摘要:A coding problem. The trick is, some part of computation can be reused from last iteration. Check out my code:#include #include #include #include #inc...
阅读全文
摘要:I tried Python:def f(x,i,n,a,b,r,s,w): if(i>n):return r return f(x,i+1,n,a*x*x,b*2*i*(2*i+s),r+a*w/b,s,-w)n=int(input())for _ in range(n): v=...
阅读全文
摘要:I saw a lot of BFS based solutions. And my alternative solution is this mirror-ed BST iterator one, with some book-keeping:class Solution {public: ...
阅读全文
摘要:Floyd-Warshall算法其实是比较容易理解也比较容易coding的DP... 不说了,上代码:#include #include #include #include #include #include #include #include #include using namespace st...
阅读全文
摘要:HihoCoder上有两道背包问题的problem,http://hihocoder.com/problemset/problem/1038 (01背包)#include #include #include #include #include #include #include using name...
阅读全文