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. ndk+opencv安装+各种错误分析(新版安装,编译不需要Cygwin 和Sequoyah了)

    鼓捣了两三天,终于成功算跑通了一个简单的程序.下面说说具体的安装: 因为从同学那里拷过来的eclipse 就有adt cdt 的插件.所以这两个就不用再安装了.(需要的话自己安装) 具体说下安装过程: ...

  2. react: next-redux-saga

    instead of using the Provider component, you can use the withRedux higher order component to inject ...

  3. PostgreSQL java读取bytes字段

    写入bytea: File img = new File("/tmp/eclipse.png"); fin = new FileInputStream(img); con = Dr ...

  4. 进程(并发,并行) join start 进程池 (同步异步)

    一.背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象.进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其他所有 ...

  5. linux之文件操作

    1. 文件操作思维导图 2. linux系统目录结构及简单说明 linux目录图: root --- 启动Linux时使用的一些核心文件.如操作系统内核.引导程序Grub等. home --- 存储普 ...

  6. mybatis 联表查询

    一.一对一关联 1.1.提出需求 根据班级id查询班级信息(带老师的信息) 1.2.创建表和数据 创建一张教师表和班级表,这里我们假设一个老师只负责教一个班,那么老师和班级之间的关系就是一种一对一的关 ...

  7. LG2120 [ZJOI2007]仓库建设

    题意 L公司有N个工厂,由高到底分布在一座山上. 工厂1在山顶,工厂N在山脚. 由于这座山处于高原内陆地区(干燥少雨),L公司一般把产品直接堆放在露天,以节省费用. 突然有一天,L公司的总裁L先生接到 ...

  8. 用python写定时任务

    一个是sched模块,一个是threading模块 参考链接:http://www.cnblogs.com/LinTeX9527/p/6181523.html

  9. linux下修改ip地址

    1.more  /etc/sysconfig/network-scripts/ifcfg-eth0 2.ifconfig eth0 192.168.1.211 netmask 255.255.255. ...

  10. Hibernate问题集锦: 概述

    Hibernate问题集锦: 概述   ImportNew注: 本文是ImportNew编译整理的Java面试题系列文章之一.你可以从这里查看全部的Java面试系列. Q.怎么配置hibernate? ...