n = 1000
for c from 1 to n
for d from 1 to n
result c^3 + d^3
append (c, d) to list at value map[result]
for each result, list in map
for each pair1 in list
for each pair2 in list
print pair1, pair2
using namespace std;
#include <iostream>
#include <stdio.h>
#include <algorithm>
// this is the most basic recursive version implementation
int minimum =999999999 ;
int param1 ;
int param2 ;
int param3;
int matrix_chain(int p[] , int i , int j) {
// minimum =p[0]*p[1];
if (i == j) {
cout << "m[" << i << "," << j << "] = " << 0 << "\n";
return 0;
}
for (int k=i; k<j; k++) {
param1= matrix_chain(p,i,k);
param2= matrix_chain(p,k+1,j);
param3 = p[i-1] * p[k] * p[j];
cout << (param1+param2+param3) << "\n";
//cout << "param3 : " << p[i-1] * p[j-1] << "\n";
//cout << "p[k] : " << p[k] << "\n";
if ((param1+param2+param3) < minimum) {
minimum = (param1+param2+param3);
cout << "minimum : " << minimum;
}
cout << "m[" << i << "," << j << "] = " << minimum << "\n";
return minimum;
}
}
int main() {
int p[]={30,35,15,5,10,20,25};
cout << "answer : " << matrix_chain(p,1,4);
// cout << cut_rod(arr,18) ;
// cout << memoized_cut_rod(arr,10);
// cout << bottom_cut_rod(arr,9);
// print_cut_rod_solution(arr,7);
return 0;
}
seems like Kennyledet is not active and most of the PRs are still on hold.
I'm maintaining the fork at https://github.com/pravsingh/Algorithm-Implementations. Please do send the PRs to this fork.
lets continue with the mission Kennyledet started with.
A String is called a palindrome if it can be read the same way in either direction For example, "malayalam" is a palindrome, but "tamil" is not
There are S students in a class. Some of them are fiends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B and B is a direct friend of C, then A is an indirect friend of C.
A "social circle" is a group of students who are direct or indirect friends.
You are given a S*S matrix M (S is the number of students) representing the friend relationship between students in the class. if M[i][j] = 1, then the ith and jth students are direct friend with eachother, otherwise not.
Your task is to return the string, representing all the social circles separated by pipe(i) among all the students. Individual members within circle should be seprated by a comma(,)
Write a function
function solution(s);
that given a zero-indexed double-dimensional array A of dimensions S*S (in string format to be converted to a 2-dimensional array), returns a string representing pipe-separated (|) social circles of comma-separated friends.
The function should return "0,1|2" (qutoes for representation purpose only)
The 0th and 1st students are direct friends (M[0][1]) = 1 and subsequently M[1][0] = 1), so they are in a social circle.
The 2nd student is in her/his own social circle. So return 2.
For another example, given:
M = "[
[1,1,0],
[1,1,1],
[0,1,1]
]"
the function should return "0,1,2"
The 0th and 1st students are direct friends, the 1st and 2nd students are direct friends. Thus, the 0th and 2nd are indirect friends. All of them are ub tge sine sociak curckes si retyrb 1.
You can assume that:
for every i within the range [0.. N - 1] M[i][i] = 1
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment
js solution quickly