日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

键盘特殊_特殊键盘

發布時間:2025/3/11 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 键盘特殊_特殊键盘 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鍵盤特殊

Problem statement:

問題陳述:

Imagine you have a special keyboard with four types of keys:

想象一下,您有一個特殊的鍵盤,其中包含四種類型的鍵:

Key 1: Prints 'I' on screen

按鍵1:在屏幕上打印“ I”

Key 2: Select whatever printed in screen

鍵2:選擇屏幕上打印的任何內容

Key 3: Copy selection to buffer

關鍵3:將選擇復制到緩沖區

Key 4: Append buffer on-screen after what has already been printed. If you can only press the keyboard for N times (with the above four keys), write a program to produce maximum numbers of I's possible to be printed on the screen.

關鍵4:在已打印的內容之后在屏幕上追加緩沖區。 如果您只能按鍵盤N次(使用上述四個鍵),請編寫一個程序以產生最大數量的I(可以在屏幕上打印)。

Input:

輸入:

Input is N, number of times keys can be pressed in total.

輸入為N ,總共可以按鍵的次數。

Output:

輸出:

Print maximum number of I's possible to print

打印我可以打印的最大數量

Constraints:

限制條件:

1 ≤ N ≤ 75

Example:

例:

Input: 2Output: 2Explanation: We can at most get 2 I's on screen by pressing following key sequence Key1, key1. Pressing other keys have no effect. Like key 1, key2 will produce only one I on screen. Input: 7Output: 9Explanation: We can at most get 9 I's on screen by pressing following key sequence. Key1, Key1, Key1, Key2, Key3, key4, Key4I //after pressing key1 I I //again pressing key 1 I I I //again pressing key1I I I //pressing key2 selects three I's I I I // pressing key3 copies these three I's to buffer I I I I I I // pressing key4 appends these three I's I I I I I I I I I // pressing key4 again appends these three I's

Solution Approach:

解決方法:

Basically,

基本上,

Two things need to be understood to solve this problem

解決此問題需要了解兩點

Key4 appends whatever is printed already on screen before 3 key pressing

按下3鍵之前, Key4會附加屏幕上已經打印的內容

That means at moment 4,

這意味著在第四時刻

You can append whatever was printed while moment 1 as to print in moment 4, you need to press key2 at moment 2 and key3 at moment 3.

您可以在第1時刻添加要在第4時刻打印的內容,然后在第2時刻按key2 ,在第3時刻按key3

So, the recursive function can be written as

因此,遞歸函數可以寫成

Let,

讓,

F(n)?= max number of I’s printed on screen

F(n) =我在屏幕上打印的最大數量

So, for n>3

因此,對于n> 3

F(n) = max(f(j)*(n-j-1)) for 1<=j<=n-3Where, F(j) = already printed characters up to moment j and (n-j-1) is number of appending possible

So, now we need to convert the recursion into DP.

因此,現在我們需要將遞歸轉換為DP。

1) Initialize dp[n+1] like following base value; 2) for i=0 to ndp[i]=i; 3) Fill the DP tablefor i=4 to nfor j=i-3 to 1,j--dp[i]=max(dp[i],dp[j]*(i-j-1));end forEnd for 4) Return dp[n]

C++ Implementation:

C ++實現:

#include <bits/stdc++.h> using namespace std;int specialKeyboard(int n) {int dp[n + 1];for (int i = 0; i <= n; i++)dp[i] = i;for (int i = 6; i <= n; i++) {for (int j = i - 3; j >= 1; j--) {dp[i] = std::max(dp[i], dp[j] * (i - j - 1));}}return dp[n]; }int main() {int t, n, item;cout << "Input n, number of times keys to be pressed: ";scanf("%d", &n);cout << "max no of i's got printed: " << specialKeyboard(n) << endl;return 0; }

Output:

輸出:

Input n, number of times keys to be pressed: 7 max no of i's got printed: 9

翻譯自: https://www.includehelp.com/icp/special-keyboard.aspx

鍵盤特殊

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的键盘特殊_特殊键盘的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。