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的更多相关文章

  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. 【scala】元组

    元组跟list类似,元组也是不可边的,但是元组可以容纳不同类型的元素. 元组用起来很简单,要实例化一个新的元组,只需要将对象放在圆括号当中,用逗号隔开即可. val pair = (99,“Luftb ...

  2. ElasticSearch6.0 Java API 使用 排序,分组 ,创建索引,添加索引数据,打分等(一)

    ElasticSearch6.0  Java API  使用     排序,分组 ,创建索引,添加索引数据,打分等 如果此文章对你有帮助,请关注一下哦 1.1 搭建maven 工程  创建web工程 ...

  3. Python输出中文到文件时的字符编码问题

    今天在使用Python的GUI平台wxPython时,写了一个只有打开.编辑.保存功能的简易笔记本,代码如下: #coding:utf-8 import wx def load(event): f = ...

  4. Arcgis for javascript map操作addLayer详解

    本节的内容很简单,说说Arcgis for Javascript里面map对象的addLayer方法.在for JS的API中,addLayer方法有两种,如下图: addLayer方法 在addLa ...

  5. Kivy: Building GUI and Mobile apps with Python

    Intro Python library for building gui apps (think qt, gdk,processing) build from ground up for lates ...

  6. struts2.5框架使用通配符指定方法,某一个匹配不到

    在学习struts框架时经常会使用到通配符调用方法,如下:但奇怪的是,在validateName请求老报404,其他的都是ok的,开始以为是配置错了,检查好久才知道: <action name= ...

  7. I.MX6 View长宽大于屏的分辨率

    /******************************************************************************** * I.MX6 View长宽大于屏的 ...

  8. 通过ssh限制ip访问

    方法:在/etc/hosts.allow中加入允许的ip,并禁止其他ip sshd:192.168.1.22:allow sshd:ALL:deny 不需要修改/etc/hosts.deny

  9. iOS6和iOS7代码的适配(5)——popOver

    popOver这个空间本身是iPad only的,所以iPhone上见不到,我记得微信上有个这样的弹出框,有扫一扫等几个菜单项,估计这是腾讯自己实现的,用于菜单的扩展. popOver从iOS6到iO ...

  10. 关于matlab浮点转定点总结

    1,算式长度不应该太长,否则在转换过程中提示位宽超过128位,(用的64位matlab),长算式改为短算式就可以了. 2,不要过于相信推荐字长,有些地方需要更高的精度,如果用推荐字长,可能结果误差较大 ...