Program to print maximum number of A’s using four keys is discussed here.
You are given a task to print maximum As with the given number of keystroke. There are four keys you use
- You can directly press A.
- You can select all the A that has been printed till now using the select all key. (Ctrl + A)
- You can copy the selected text. (Ctrl + C)
- You can paste the copied text. (Ctr + V)
- Now, once copied, you can paste it any number of time but each time it will take one keystroke.
Sample Input: 7 (Number of times we can press the key)
Sample Output: 9
A A A Ctrl+A Ctrl+C Ctrl+V Ctrl+V
By following this sequence, A can be printed 9 times.
Algorithm to print maximum number of A,s using four keys
- Input N, number of times the key can be used.
- For N <= 6, return N as the maximum value.
- For N > 6, try all combinations and store the value in a temporary variable.
- Keep updating the temporary variable until all combinations have been applied.
- Print the temporary variable.
Program to print the maximum number of A’s using the given keys is given below.
/* C++ program to print the maximum number of A’s using the given keys */
using namespace std;
long int dp[n];
if(temp > dp[i-1])