hope this works :
#include<stdio.h>
#define MAX(A,B) A>B?A:B
#define MIN(A,B) A<B?A:B
int FindMaxA(int n)
{
int i,k,factor,max = 0,cur,prev;
int* arr = new int[n+1];
int p = MIN(n,4);
for( int j = 1;j <= p;j++)
arr[j] = j;
for(i=5;i<=n;i++)
{
k = i-4;
factor = 2;
prev = 0;
while(k>=1)
{
cur = arr[k]*factor;
if( cur > max ) //find max among multiples of Arr[k] for k < i
max = cur;
if( cur < prev )
break; // once the decreasing pattern starts its safe to
break out of loop.
k--;
factor++;
prev = cur;
}
arr[i] = MAX(i,max);
}
int result = arr[n];
delete[] arr;
return result;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d\n",FindMaxA(n));
return 0;
}
------------------------------------------------------------------------------------------------------
On Fri, Jan 21, 2011 at 11:28 AM, Preetam Purbia
<[email protected]>wrote:
> Hi,
>
> I think this method will work
>
Possible Number of A's = N/2(1+R)
> where R=N-(N/2+3)
>
> assuming 11/2 = 5
>
> Thanks
> Preetam
>
>
> On Fri, Jan 21, 2011 at 2:29 AM, Anand <[email protected]> wrote:
>
>> but my output : m =20: For first 5 times hit 'A', then ctrl+A, ctrl+C
>> resulting in 7 keystrokes. then 3 times ctrl+V, which result in m = 20.
>>
>> Try this on a notepad. you will only 15A's
>>
>>
>> On Thu, Jan 20, 2011 at 12:46 PM, Saikat Debnath <[email protected]>wrote:
>>
>>> According to me Nishaanth's solution is incorrect, as let for n =10, your
>>> output : m=16
>>> but my output : m =20: For first 5 times hit 'A', then ctrl+A, ctrl+C
>>> resulting in 7 keystrokes. then 3 times ctrl+V, which result in m = 20.
>>>
>>>
>>> On Thu, Jan 20, 2011 at 9:24 PM, abhijith reddy d <
>>> [email protected]> wrote:
>>>
>>>> I think its correct.
>>>>
>>>> On Jan 19, 9:35 pm, nishaanth <[email protected]> wrote:
>>>> > How about the following dynamic programming solution.
>>>> >
>>>> > Let dp[i] be the max no of As with i keystrokes.
>>>> >
>>>> > dp[i]=max(dp[i-1]+1,2*dp[i-3])
>>>> >
>>>> > dp[N] is the required solution.
>>>> >
>>>> > Correct me if i am wrong.
>>>> >
>>>> >
>>>> >
>>>> > On Wed, Jan 19, 2011 at 9:20 PM, Raj <[email protected]>
>>>> wrote:
>>>> > >http://www.ihas1337code.com/2011/01/ctrla-ctrlc-ctrlv.html
>>>> >
>>>> > > On Jan 19, 8:28 pm, bittu <[email protected]> wrote:
>>>> > > > Given
>>>> >
>>>> > > > 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).
>>>> >
>>>> > > > Thanks & Regards
>>>> > > > Shashank Mani
>>>> >
>>>> > > --
>>>> > > You received this message because you are subscribed to the Google
>>>> Groups
>>>> > > "Algorithm Geeks" group.
>>>> > > To post to this group, send email to [email protected].
>>>> > > To unsubscribe from this group, send email to
>>>> > > [email protected]<algogeeks%[email protected]>
>>>> <algogeeks%[email protected]<algogeeks%[email protected]>
>>>> >
>>>> > > .
>>>> > > For more options, visit this group at
>>>> > >http://groups.google.com/group/algogeeks?hl=en.
>>>> >
>>>> > --
>>>> > S.Nishaanth,
>>>> > Computer Science and engineering,
>>>> > IIT Madras.
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<algogeeks%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>>
>>>
>>>
>>> --
>>> Regards
>>> Saikat Kumar Debnath
>>> IIIrd year, Computer Science Deptt.,
>>> Delhi Technological University,
>>> (formerly Delhi College of Engineering)
>>> Delhi
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<algogeeks%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Preetam Purbia
> http://twitter.com/preetam_purbia
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.