[抄题]:

Imagine you have a special keyboard with the following keys:

Key 1: (A): Print one 'A' on screen.

Key 2: (Ctrl-A): Select the whole screen.

Key 3: (Ctrl-C): Copy selection to buffer.

Key 4: (Ctrl-V): Print buffer on screen appending it after what has already been printed.

Now, you can only press the keyboard for N times (with the above four keys), find out the maximum numbers of 'A' you can print on screen.

Example 1:

Input: N = 3
Output: 3
Explanation:
We can at most get 3 A's on screen by pressing following key sequence:
A, A, A

Example 2:

Input: N = 7
Output: 9
Explanation:
We can at most get 9 A's on screen by pressing following key sequence:
A, A, A, Ctrl A, Ctrl C, Ctrl V, Ctrl V

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

贪心算法可以从除法 and 乘法的角度来思考

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[一句话思路]:

因为要做全选、拷贝、粘贴:三个数以内要进行相乘

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

复制粘贴不是乘法就是除法

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

[潜台词] :

class Solution {
public int maxA(int N) {
int max = N;
for (int i = 1; i <= N - 3; i++) {
max = Math.max(max, maxA(i) * (N - i - 1));
}
return max;
}
}

651. 4 Keys Keyboard复制粘贴获得的最大长度的更多相关文章

  1. 650. 2 Keys Keyboard复制粘贴的次数

    [抄题]: Initially on a notepad only one character 'A' is present. You can perform two operations on th ...

  2. [LeetCode] 651. 4 Keys Keyboard 四键的键盘

    Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...

  3. [LeetCode] 4 Keys Keyboard 四键的键盘

    Imagine you have a special keyboard with the following keys: Key 1: (A): Print one 'A' on screen. Ke ...

  4. [LeetCode] 2 Keys Keyboard 两键的键盘

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  5. Leetcode 之 Keys Keyboard

    1. 2 Keys Keyboard 先把dp的最小不走都设置为无穷大(Integer.MAX_VALUE),初始化条件:dp[0] = dp[1] = 0,状态转移方程为dp[i] = Math.m ...

  6. [leetcode] 650. 2 Keys Keyboard (Medium)

    解法一: 暴力DFS搜索,对每一步进行复制还是粘贴的状态进行遍历. 注意剪枝的地方: 1.当前A数量大于目标数量,停止搜索 2.当前剪贴板数字大于等于A数量时,只搜索下一步为粘贴的状态. Runtim ...

  7. [LeetCode] 650. 2 Keys Keyboard 两键的键盘

    Initially on a notepad only one character 'A' is present. You can perform two operations on this not ...

  8. vi的复制粘贴命令 -- (转)

    vi编辑器有3种模式:命令模式.输入模式.末行模式.掌握这三种模式十分重要: 1.命令模式:vi启动后默认进入的是命令模式,从这个模式使用命令可以切换到另外两种模式,同时无论在任何模式下只要按一下[E ...

  9. 在Mac中设置Ctrl+C/V进行复制/粘贴

    从Windows世界走入Mac世界,最让不习惯的是在Mac中“复制/粘贴”的快捷键是Command+C/V.而且Command键与C/V键靠得太近,只能用大拇指与食指进行操作,也让人不习惯.再加上远程 ...

随机推荐

  1. day51 django第二天 django初识

    一.模块渲染  jinja2 实现简单的字符串替换(动态页面) 1.下载 pip install jinja2 示例 : html文件中 <!DOCTYPE html> <html ...

  2. awk命令过滤tomcat的访日日志中IP地址

    1. 命令如下 批量过滤日志文件,grep -v是要排除10网段开头的IP地址 sort会自动按ip排序 uniq -c去重并计数 sort -n 按数值从小到大排序 [root@linux-node ...

  3. 引入public文件目錄下js/css文件

    <link href="{{ URL::asset('css/ySelect.css') }}" rel="stylesheet" type=" ...

  4. Intellij中部署Tomcat(详细版本-介绍了部署完之后的详细路径)

    https://blog.csdn.net/HughGilbert/article/details/56424137 要点如下: 1. CATALINA_HOME即Tomcat的安装目录 2. CAT ...

  5. 学习笔记之机器学习(Machine Learning)

    机器学习 - 维基百科,自由的百科全书 https://zh.wikipedia.org/wiki/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0 机器学习是人工智能的一个分 ...

  6. 知识点:Mysql 基本用法之流程控制

    流程控制 一. 条件语句 if 语句实例: delimiter // CREATE PROCEDURE proc_if () BEGIN declare i int default 0; if i = ...

  7. python网络爬虫学习笔记(一)Request库

    一.Requests库的基本说明 引入Rquests库的代码如下 import requests 库中支持REQUEST, GET, HEAD, POST, PUT, PATCH, DELETE共7个 ...

  8. ipv6无网络访问权限怎么办

    有时IP4和IP6都正常连接,但突然又出现“IPV6无网络访问权限” 这是win7系统下经常发生的事情,如下图. 方法/步骤 1.IPV6没网络权限是正常的因为你没有IPV6的网络环境,那个只有部分教 ...

  9. Maven CXF wsdl2java XMLGregorianCalendar类型更改

    jaxb-bindings.xml配置: <?xml version="1.0" encoding="UTF-8"?> <jaxb:bindi ...

  10. Java面试——线程池

    1.类比介绍 假如有一个工厂,工厂里面有10个工人,每个工人同时只能做一件任务. 因此只要当10个工人中有工人是空闲的,来了任务就分配给空闲的工人做: 当10个工人都有任务在做时,如果还来了任务,就把 ...