I’m trying to solve the following algorithmic problem: I’m given an array (it could be a standard C/C++ array, a vector<vector<T> >, or something else… whatever is most suited to this problem is fine) populated with random non-zero values. I know the size of the array, m x n. What I want to do is ..

#### Category : algorithm

I hava a linked list: struct Node { bool isEmpty; int size; struct Node *next; } the nodes are like a tree in the way for example : 4->4->8->16->16->16->64 How can i check for example that if nodes in bold are empty combine them together. Nodes can be murged only if : are empty have ..

question sample input/output first line is N K A B second line is s[i] for(int i=1;i<=N;i++){ for(int j=1;j<=K;j++){ long long tmp=A*max(0,B-abs(i-dp[i-1][j-1].path[dp[i-1][j-1].path.size()-1]); if(s[i]+dp[i-1][j-1]+tmp>dp[i-1][j]){ dp[i][j]=s[i]+dp[i-1][j-1]+tmp; }else{ dp[i][j]=dp[i-1][j]; } } I solve this problem using dp like 0/1 knapsack problem. But the case A*max(0,B-(xi+1-xi)) makes dp can’t work. I think my substructure of dp is wrong. Is there ..

Given F(0) = 0, F(1) = 1, F(2) = 2, F(3)=3 and F(n) = (F(n−1)−F(n−3) +F(n−4)))%m. Task is to implement an efficient algorithm to compute F(n) where n is a 10^5 bit number given in the binary representation and m < 10^6 #include<bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { /* input ..

I am currenly learning the Sprague-Grundy theorem of Game theory. But I am not able to understand how to apply it in questions. For example in the following question GAME3 Two girls – Ivica and Marica – play an interesting game. First, they randomly choose a natural number N. They also define M = 1. ..

I need to draw the closest thing to a major diagonal on a picture(irregular matrix). I already know that for a regular one the format is the following: for (i = 0; i < row; i++) { for (j = 0; j < column; j++) { if(i==j){ matrix[row][column] = color_of_diagonal; } } } But adapt ..

Binary-Decimal We are given a binary string S of length n, in which each character is either ‘1’ or ‘0’. And we are asked to perform several queries on the string. In each query we are given integers L and R. And we have to tell the value of sub-string S[l..r], in decimal representation. Sample ..

The first line of the standard input contains the number of elements(N) (1<=N<=100). The next lines contain a number (M) (1<=M<=300), as we know, there can be maximum 100 "M" elements. We need to find the smallest number, that is smaller than 120. In the first line of the standard output, we need to print ..

To describe my problem: Consider I have an input array A[4,5,2,7,1,2] and M=3. We can group an array A such that G[1,…m]. That means if M=3, then one of the group combinations can be G[2,3,1] (the size of G is given by M and the sum of these elements should be equal to the size ..

A directed graph is given as an input, in the output I need to cout all the SCC of the input graph and its condensation graph. I have written Graph class and Kosarayu algorithm to find strongly connected components in a directed graph. The question is – how can I find and cout graph condensation ..

## Recent Comments