1. public class Solution {
  2. public int GetMoneyAmount(int n)
  3. {
  4. int[,] table = new int[n + , n + ];
  5. return DP(table, , n);
  6. }
  7.  
  8. int DP(int[,] t, int s, int e)
  9. {
  10. if (s >= e) return ;
  11. if (t[s, e] != ) return t[s, e];
  12. int res = int.MaxValue;
  13. for (int x = s; x <= e; x++)
  14. {
  15. int tmp = x + Math.Max(DP(t, s, x - ), DP(t, x + , e));
  16. res = Math.Min(res, tmp);
  17. }
  18. t[s, e] = res;
  19. return res;
  20. }
  21. }
  1. public class Solution {
  2. public int GetMoneyAmount(int n)
  3. {
  4. int[,] table = new int[n + , n + ];
  5. for (int j = ; j <= n; j++)
  6. {
  7. for (int i = j - ; i > ; i--)
  8. {
  9. int globalMin = int.MaxValue;
  10. for (int k = i + ; k < j; k++)
  11. {
  12. int localMax = k + Math.Max(table[i, k - ], table[k + , j]);
  13. globalMin = Math.Min(globalMin, localMax);
  14. }
  15. table[i, j] = i + == j ? i : globalMin;
  16. }
  17. }
  18. return table[, n];
  19. }
  20. }

https://leetcode.com/problems/guess-number-higher-or-lower-ii/#/description

leetcode375的更多相关文章

  1. [Swift]LeetCode375. 猜数字大小 II | Guess Number Higher or Lower II

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  2. leetcode375 Guess Number Higher or Lower II

    思路: dp. https://leetcode.com/problems/guess-number-higher-or-lower-ii/discuss/ 实现: class Solution { ...

随机推荐

  1. 【spark】RDD操作

    RDD操作分为转换操作和行动操作. 对于RDD而言,每一次的转化操作都会产生不同的RDD,供一个操作使用. 我们每次转换得到的RDD是惰性求值的 也就是说,整个转换过程并不是会真正的去计算,而是只记录 ...

  2. Struts07---访问servlet的API

    01.创建登录界面 <%@ page language="java" import="java.util.*" pageEncoding="UT ...

  3. UIView常用属性与方法/UIKit继承结构

    UIView常用属性与方法 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDy ...

  4. Activity Process Task Application 专题讲解

    Activity Process Task Application 专题讲解 Activity.和进程 为了阅读方便,将文档转成pdf http://files.cnblogs.com/franksu ...

  5. [转载]Python注册表信息丢失的解决方案

    今天安装Python的模块时,安装失败,提示信息:Python version 2.7 required, which was not found in the registry. 原因在于Pytho ...

  6. 使用LNMP环境安装typecho博客的全程记录

    虽然我是搞asp.net的 但是十分欣赏php,php有很多开源的博客程序 比如大名鼎鼎的Wordpress.还有各种独立博客大牛使用的z-blog,以及短小精悍的emblog. wordpress臃 ...

  7. [转载]Lwip之IP/MAC地址冲突检测

    from: http://blog.csdn.net/tianjueyiyi/article/details/51097447 LWIP是个轻量级的TCP/IP协议栈,之所以说轻量级,是因为作者将主体 ...

  8. uid

    var uid = 0 function nextUid() { return ++uid }

  9. UVA136 Ugly Numbers

    题意 PDF 分析 用堆和集合维护即可. 时间复杂度\(O(1500 \log n)\) 代码 #include<iostream> #include<cstdio> #inc ...

  10. WPF 自定义DateControl DateTime控件(转)

    自定义日期控件,月份选择.如下是日期的一些效果图. 具体的样式.颜色可以根据下面的代码,自己调节即可    1.日期控件的界面 <UserControl x:Class="WpfApp ...