摘要:
题目链接:Coin on the Table一开始想用DFS做的,做了好久都超时。看了题解才明白要用动态规划。设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的最小改动,那么递推式如下:图片来源:Editorial,其中当从周围的格子可以直接移动到(i,j)时,de... 阅读全文
摘要:
题目链接:Cut the tree题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小。暴力求解会超时。如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a,b)的时候,其中的一棵树必是以a或者b为根的子树,那么我们就可以知道生成的两棵树的节点之和了。所以,当我... 阅读全文
摘要:
Numeros, The Artist, had two listsAandB, such that,Bwas a permutation ofA. Numeros was very proud of these lists. Unfortunately, while transporting th... 阅读全文
摘要:
Sorting is often useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses als... 阅读全文
摘要:
In the Quicksort challenges, you sorted an entire array. Sometimes, you just need specific information about a list of numbers, and doing a full sort ... 阅读全文
摘要:
One classic method for composing secret messages is called a square code. The spaces are removed from the english textand the characters are written i... 阅读全文
摘要:
Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N flavors available, they have to choose two distinc... 阅读全文