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. 【spark】连接Hbase

    0.我们有这样一个表,表名为Student 1.在Hbase中创建一个表 表明为student,列族为info 2.插入数据 我们这里采用put来插入数据 格式如下   put  ‘表命’,‘行键’, ...

  2. fastjson缺陷--map转换json时出现$ref的情况

    DisableCircularReferenceDetect来禁止循环引用检测: JSON.toJSONString(..., SerializerFeature.DisableCircularRef ...

  3. 前端之CSS续集

    CSS:语法形式上由选择器+以及一条或多条声明组成:选择器查找到指定的html标签后,使用css属性设置html标签的样式: 一.css 语法形式: 二.使用步骤   1.引入css规则 2.使用cs ...

  4. OC-协议与代理

    [协议]================================================================ @protocol [协议的作用]:规定了需要实现的接口方法, ...

  5. 剑指offer--32.把数组排成最小的数

    用to_string()将整形转化为字符串,对字符串进行比较 --------------------------------------------------------------------- ...

  6. MASM 16位汇编程序几种典型的格式

    1.有名段 data segment output db 'Hello world!$' data ends code segment start: assume ds:data,cs:code mo ...

  7. Scikit-Learn:开源的机器学习Python模块(转载)

    摘要: scikit-learn是一个用于机器学习的Python模块,其具有操作简单.效率高.无访问限制.BSD开源协议等等特征,在机器学习这一块是比较受欢迎的. scikit-learn是一个用于机 ...

  8. Near Field Communication (NFC) applications

    Near Field Communication (NFC) applications There has been little practical guidance available on NF ...

  9. HDU - 3374:String Problem (最小表示法模板题)

    Give you a string with length N, you can generate N strings by left shifts. For example let consider ...

  10. HihoCoder 1183 : 连通性一·割边与割点(模板)

    连通性一·割边与割点 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 还记得上次小Hi和小Ho学校被黑客攻击的事情么,那一次攻击最后造成了学校网络数据的丢失.为了避免再次 ...