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 { ...
随机推荐
- STM32F103: NRF24L01
看了两天的24l01的相关资料了,一直有点模糊,今天下午感觉有点懂了,在板子上调试成功了,但是还没进行通讯测试.stm32和arduino进行通信还没成功 ,:( 先把stm32的NRF24L01配置 ...
- debounce与throttle区别
在2011年,Twitter网站曾爆出一个问题:在主页往下滚动时,页面会变得缓慢以致没有响应.John Resig发表了一篇文章< a blog post about the problem&g ...
- 看过自会理解, Photon Server 常见概念分析.
http://stackoverflow.com/questions/10823915/photon-server-newbie-questions/11653419#11653419 Channel ...
- UltraEdit编码设置
1.查看ue文件编码 一直苦于无法判断文件的编码类型,现在发现一个方法,就是用强大的UltraEdit-32软件: UltraEdit-32的状态栏可以显示文件的编码类型,详细情况如下: ANSCI- ...
- ORM版,学生信息管理单表查询..
mysql 建学生表及课程表 添加内容 view.py from django.shortcuts import render,HttpResponse,redirect from . import ...
- (效果一)js实现上拉加载
实现思路:获取滚动元素的高度,滚动条距离顶部的距离,滚动条的高度, 算式:可视窗口的高度 + 滚动条距离顶部的距离 == 滚动条的高度就说明到底部. HTML <!doctype html> ...
- (六)java数据类型
数据类型:决定了变量占据多大的空间,决定了变量存储什么类型的数据 整形: byte 1个字节 short 2个字节 int 4个字节 long 8个字节 浮点型 ...
- bzoj 3124 直径
Written with StackEdit. Description 小\(Q\)最近学习了一些图论知识.根据课本,有如下定义. 树:无回路且连通的无向图,每条边都有正整数的权值来表示其长度.如果一 ...
- ERP与MES
EAS-ERP企业资源计划系统 能将企业的客户管理.商品管理.采购管理.仓储管理.销售管理.生产管理.应收应付.财务管理.工资管理.费用管理和业绩考核管理以及业务预警和全方位的分析汇总融为一体,为企业 ...
- JAMstack 最佳实践
摘自官方介绍,没有翻译(没必要,已经比较简单了,重要的就是进行每条的诠释了,后续...) Entire Project on a CDN Because JAMstack projects don’t ...