1. A
2. Ctrl+A
3. Ctrl+C
4. Ctrl+V
If you can only press the keyboard for N times (with the above four keys), please write a program to produce maximum numbers of A. If possible, please also print out the sequence of keys.
So the input parameter is N (No. of keys that you can press), the output is M (No. of As that you can produce).
int fun(int n)
{
int buf[100][4];
memset(buf, 0, sizeof(buf));
buf[0][0] = 1;
for (int i = 1; i < n; i++)
{
for (int j = 0; j < 4; j++)
{
for (int k = 0; k < 4; k++)
{
if (j == 0)//A
{
buf[i][j] = max(buf[i][j], buf[i-1][k] + 1);
}
else if (j == 1)//CTRL + A
{
buf[i][j] = max(buf[i][j], buf[i-1][k]);
}
else if (j == 2)//CTRL + C
{
if (k == 1)
{
buf[i][j] = max(buf[i][j], buf[i-1][k]);
}
}
else//CTRL + V
{
if (k == 2)
{
buf[i][j] = max(buf[i][j], buf[i-1][k] *2);
}
}
}
}
}
return max(buf[n-1][3], buf[n-1][0]);
}