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 { ...
随机推荐
- vi编辑器:命令模式、输入模式、末行模式
1.命令模式(command mode)—执行命令 在该模式中,可以输入命令来执行许多种功能.控制屏幕光标的移动,字符.字或行的删除,移动复制某区段及进入Insert mode下,或者到 last l ...
- flex 弹性布局的大坑!!
如果父元素设置 display:flex,那么其中的子元素会被当成行内元素对待,即会忽略其宽度 这在设置背景图时要特别特别注意!!!!
- (三)java程序的编译和执行
编写java程序 eg class Demo { /* * 程序运行的入口 */ public static void main(String[] args) { System.out.println ...
- BJOI2019 游记
BJOI 2019 游记 Day 1 开场拿到 \(T1\) 发现可以转成求平均 \(log\) 直接 \(AC\) 自动机上 \(Dp\) 一波即可 \(T2\) 发现是到数论神仙题,大概能想到要用 ...
- linux离线搭建Python环境及安装numpy、pandas
1.安装python2.7.3 Cent OS 6.5默认装的有python2.6.6,需要重新安装python2.7.3下载地址:https://www.python.org/downloads/s ...
- 谨慎安装Python3.7.0,SSL低版本导致Pip无法使用
最新新配置了一台服务器.安装 的时候直接使用了最新的Python 3.7最新版本. 安装成功,编译成功.但是用pip 安装包的时候提示:pip is configured with locations ...
- World、Excel利用流下载
/** * 下载excel * @param request * @param response * @param filePath * @param fileName */public static ...
- 12C中Profile的使用
12c中PROFILE在PDB和CDB中是公用的,不过创建的profile名称在CDB和PDB有所不同. 如: 1.CDB中创建Profile SQL> show con_name CON_NA ...
- 网络服务器带宽Mbps、Mb/s、MB/s的区别
例如所谓 10M 带宽,其实是指 10Mbps (兆比特) 计算带宽理论最快下载速度:10÷8=1.25MB/s 那么100M的带宽最快下载速度是12.5MB/s. 但这只是理论上的速度,在这个数值附 ...
- oracle驱动包maven下载失败解决
oracle是付费的,因此jar包也不是随便让人下的,这就给maven的下载和编译带来了麻烦,因为我们没法从maven仓库直接拿来用.解决办法就是先从别的地方获取jar包,再放到本地仓库里去,这样运行 ...