[LeetCode] Strange Printer 奇怪的打印机

There is a strange printer with the following two special requirements:

  1. The printer can only print a sequence of the same character each time.
  2. At each turn, the printer can print new characters starting from and ending at any places, and will cover the original existing characters.

Given a string consists of lower English letters only, your job is to count the minimum number of turns the printer needed in order to print it.

Example 1:

Input: "aaabbb"
Output: 2
Explanation: Print "aaa" first and then print "bbb".

Example 2:

Input: "aba"
Output: 2
Explanation: Print "aaa" first and then print "b" from the second place of the string, which will cover the existing character ‘a‘.

Hint: Length of the given string will not exceed 100.

s

原文地址:https://www.cnblogs.com/grandyang/p/8319913.html

时间: 2024-10-10 06:06:26

[LeetCode] Strange Printer 奇怪的打印机的相关文章

leetcode 664. Strange Printer

There is a strange printer with the following two special requirements: The printer can only print a sequence of the same character each time. At each turn, the printer can print new characters starting from and ending at any places, and will cover t

HDU 1548 A strange lift 奇怪的电梯(BFS,水)

题意:有一座电梯,其中楼层从1-n,每层都有一个数字k,当处于某一层时,只能往上走k层,或者下走k层.楼主在a层,问是否能到达第b层? 思路:在起点时只能往上走和往下走两个选择,之后的每层都是这样,那么就类似于二叉树.每个节点就是对应的层,因为有可能碰到循环的层,比如1跳到3,3跳回1,这样使得无限循环,所以加个vis数组标记是否遍历过即可. 1 #include <iostream> 2 #include <cmath> 3 #include <cstring> 4

664. Strange Printer

class Solution { public: int dp[100][100]; int dfs(const string &s, int i,int j) { if(i>j)return 0; if(dp[i][j])return dp[i][j]; dp[i][j]=dfs(s,i,j-1)+1; for(int k=i;k<j;++k) { if(s[k]==s[j])dp[i][j]=min(dp[i][j],dfs(s,i,k)+dfs(s,k+1,j-1)); } re

【LeetCode】动态规划(下篇共39题)

[600] Non-negative Integers without Consecutive Ones [629] K Inverse Pairs Array [638] Shopping Offers [639] Decode Ways II [646] Maximum Length of Pair Chain [647] Palindromic Substrings [650] 2 Keys Keyboard [651] 4 Keys Keyboard [656] Coin Path [6

【Leetcode周赛】从contest-41开始。(一般是10个contest写一篇文章)

Contest 41 ()(题号) Contest 42 ()(题号) Contest 43 ()(题号) Contest 44 (2018年12月6日,周四上午)(题号653-656) 链接:https://leetcode.com/contest/leetcode-weekly-contest-44 比赛情况记录:就做出来两题,第三题不难,然而就是在算坐标的时候卡住了.orz.结果:2/4,ranking:637/2272.第四题没看题,第三题搞得心情不好了orz. [653]Two Sum

(转)设置默认打印机

type TForm1 = class(TForm) Button1: TButton; ComboBox1: TComboBox; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; {...} procedure TForm1.FormCreate(

Centos下samba共享打印机

先说需求,公司有一台型号为HP LaserJet m1120 mfp的打印机,由于不是网络打印机使用起来十分不便,公司老大要求将这台打印机连在公司的内网linux服务器上(CentOS),然后配置samba共享打印机.下面开工,主要分三大步骤,如符合你的需求,请继续阅读. 第一步,要保证你的打印机在linux服务器上可以正常打印.1.公司的惠普打印机连接埠为USB,将打印机插在服务器上,可以看到/dev/usb/lp0就是我的打印机2.到http://www.linuxprinting.org/

LeetCode Problems List 题目汇总

No. Title Level Rate 1 Two Sum Medium 17.70% 2 Add Two Numbers Medium 21.10% 3 Longest Substring Without Repeating Characters Medium 20.60% 4 Median of Two Sorted Arrays Hard 17.40% 5 Longest Palindromic Substring Medium 20.70% 6 ZigZag Conversion Ea

C# winForm 修改默认打印机(效果不太好,每次修改都会有一个系统的打印弹窗(win10))

1.界面:1个按钮+1个combobox; 2.开头阴影 using System.Runtime.InteropServices; 3.代码 private void Form1_Load(object sender, EventArgs e) { InitprinterComboBox(); //初始化打印机下拉列表选项 } private void InitprinterComboBox() {// 初始化打印机列表 PrintDocument printDocument = new Pr