leetcode375
- public class Solution {
- public int GetMoneyAmount(int n)
- {
- int[,] table = new int[n + , n + ];
- return DP(table, , n);
- }
- int DP(int[,] t, int s, int e)
- {
- if (s >= e) return ;
- if (t[s, e] != ) return t[s, e];
- int res = int.MaxValue;
- for (int x = s; x <= e; x++)
- {
- int tmp = x + Math.Max(DP(t, s, x - ), DP(t, x + , e));
- res = Math.Min(res, tmp);
- }
- t[s, e] = res;
- return res;
- }
- }
- public class Solution {
- public int GetMoneyAmount(int n)
- {
- int[,] table = new int[n + , n + ];
- for (int j = ; j <= n; j++)
- {
- for (int i = j - ; i > ; i--)
- {
- int globalMin = int.MaxValue;
- for (int k = i + ; k < j; k++)
- {
- int localMax = k + Math.Max(table[i, k - ], table[k + , j]);
- globalMin = Math.Min(globalMin, localMax);
- }
- table[i, j] = i + == j ? i : globalMin;
- }
- }
- return table[, n];
- }
- }
https://leetcode.com/problems/guess-number-higher-or-lower-ii/#/description
leetcode375的更多相关文章
- [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 ...
- leetcode375 Guess Number Higher or Lower II
思路: dp. https://leetcode.com/problems/guess-number-higher-or-lower-ii/discuss/ 实现: class Solution { ...
随机推荐
- 【spark】RDD操作
RDD操作分为转换操作和行动操作. 对于RDD而言,每一次的转化操作都会产生不同的RDD,供一个操作使用. 我们每次转换得到的RDD是惰性求值的 也就是说,整个转换过程并不是会真正的去计算,而是只记录 ...
- Struts07---访问servlet的API
01.创建登录界面 <%@ page language="java" import="java.util.*" pageEncoding="UT ...
- UIView常用属性与方法/UIKit继承结构
UIView常用属性与方法 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDy ...
- Activity Process Task Application 专题讲解
Activity Process Task Application 专题讲解 Activity.和进程 为了阅读方便,将文档转成pdf http://files.cnblogs.com/franksu ...
- [转载]Python注册表信息丢失的解决方案
今天安装Python的模块时,安装失败,提示信息:Python version 2.7 required, which was not found in the registry. 原因在于Pytho ...
- 使用LNMP环境安装typecho博客的全程记录
虽然我是搞asp.net的 但是十分欣赏php,php有很多开源的博客程序 比如大名鼎鼎的Wordpress.还有各种独立博客大牛使用的z-blog,以及短小精悍的emblog. wordpress臃 ...
- [转载]Lwip之IP/MAC地址冲突检测
from: http://blog.csdn.net/tianjueyiyi/article/details/51097447 LWIP是个轻量级的TCP/IP协议栈,之所以说轻量级,是因为作者将主体 ...
- uid
var uid = 0 function nextUid() { return ++uid }
- UVA136 Ugly Numbers
题意 PDF 分析 用堆和集合维护即可. 时间复杂度\(O(1500 \log n)\) 代码 #include<iostream> #include<cstdio> #inc ...
- WPF 自定义DateControl DateTime控件(转)
自定义日期控件,月份选择.如下是日期的一些效果图. 具体的样式.颜色可以根据下面的代码,自己调节即可 1.日期控件的界面 <UserControl x:Class="WpfApp ...