CTRL+A, CTRL+C, CTRL+V

Code given by does not give desired output.. pleas…

Anonymous - May 3, 2014

Code given by does not give desired output.. please check the code given below working fine.

int MaxCopy(int n){
int *table=(int *)malloc(sizeof(int)*(n+1));
memset(table,0,sizeof(int)*(n+1));

for(int i=0;i<=n;i++){
table[i]=i;
}
for(int i=0;i<=n;i++){
for(int j=i+4;j<=n;j++){
table[j]=max(table[j],table[i]*(j-i-2));
}
}
int res=table[n];
free(table);
return res;
}

Thanks man for fixing it. I will update it soon.

CTRL+A, CTRL+C, CTRL+V

Problem Imagine you have a special keyboard with the following keys:  A Ctrl+A Ctrl+C Ctrl+V where CTRL+A, CTRL+C, CTRL+V each acts as one function key for “Select All”, “Copy”, and “Paste” operations respectively. 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. That is to say, the input parameter is N (No. [Read More]

Petrol Bunk in a Circle.

Problem You have a circular track containing fuel pits at irregular intervals. The total amount of fuel available from all the pits together is just sufficient to travel round the track and finish where you started. Given the the circuit perimeter, list of each fuel pit location and the amount of fuel they contain, find the optimal start point on the track such that you never run out of fuel and complete circuit. [Read More]

Maximum size square sub-matrix with all 1s

Question: Given a matrix consisting only 0s and 1s, find the maximum size square sub-matrix with all 1s. Example: Consider the below matrix. 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0 The maximum square sub-matrix with all ‘1’ bits is from (2,1) to (4,3) 1 1 1 1 1 1 1 1 1 Answer: [Read More]

Longest increasing subsequence

Longest Increasing Subsequence has been a classic Dynamic Programming problem. O(N^2) has been around for a while but more interesting is the following O(n log n) solution. Problem Input : Sequence of integers (or any comparable items) Output : Longest increasing subsequence of the sequence, which may not be contiguous. For example : We have sequence : 1,8,2,7,3,6,4,5 which has the longest increasing subsequence : 1,2,3,4,5. Note that the numbers are non-contiguous. [Read More]