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. Qt类型转换

    (转自:http://qimo601.iteye.com/blog/1260479) 1.char * 与 const char *的转换 char *ch1="hello11"; ...

  2. 猪齿鱼_01_环境搭建(二)_微服务支撑组件部署(Docker形式)

    一.前言 上一节,我们以源码形式部署好了猪齿鱼微服务组件,过程繁琐,且启动后占用了服务器大量的资源,对开发极其不友好.

  3. python基础之模块二

    六 logging模块 6.1 函数式简单配置 import logging #导入模块 logging.debug('debug message') #调试消息 logging.debug('inf ...

  4. LeetCode OJ:Perfect Squares(完美平方)

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  5. AFNetworking网络请求与图片上传工具(POST)

    AFNetworking网络请求与图片上传工具(POST) .h文件 #import <Foundation/Foundation.h> /** 成功Block */ typedef vo ...

  6. Framework、Cocoa、Xcode

    什么是Cocoa? NeXTSTEP(以Unix作为内核的操作系统)内置的许多库(libraries)和工具,让程序员以一种优雅的方式与窗口管理器进行交互,这些libraries叫做Framework ...

  7. Tinymce group plugin

    本文介绍一个tinymce插件,用来组合显示下拉的按钮.基于4.x,不兼容3.x. 以前 配置toolbar功能按钮 需要          toolbar1: "code undo red ...

  8. Mac上安装Jenkins持续部署初体验

    1.首先去官网下载安装包 https://jenkins.io/doc/book/installing/ 安装完成后,很不幸,无法访问他的默认站点 查了一堆资料,有的说环境变量没有配置,有的说没有执行 ...

  9. NOIP模拟题 管道

    题目大意 给定$n$个点的无向图,求它的$Dfs$序方案数$n\leq 18$ 题解 状压$Dp+$记忆化搜索. 设$F_{i,now}$表示到达$i$其中$now$集合代表的点集已经遍历过,还需要遍 ...

  10. Microsoft Office 2013 (64位) 免费完整版(安装 + 激活)

    Microsoft Office 2013(Office 15)是微软的新一代Office办公软件,全面采用Metro界面.Microsoft Office 2013官方下载(Office2013专业 ...