Recursion dp function does not work if the base cases are not ordered properly. Make sure **if(r>2) return -infinity; **is first in the recursive function. Here, r is the number of games already played consecutively.

Active In

International Olympiad in Informatics

Machine Learning

Deep Learning

Artificial Intelligence

Algorithms and Data Structures

Competitive Programming

Featured Contributions

comment in this discussion

Recursion dp function does not work if the base cases are not ordered properly. Make sure **if(r>2) return -infinity; **is first in the recursive function. Here, r is the number of games already played consecutively.

Read more… (35 words)

comment in this discussion

I came up with a different algorithm, but it is only working for the first case. Could anyone point out the flaw?

Logic → Create an array sums[], which for 'i' gives the sum of all the the teams from (i+1) to n. This can be used to calculate the revenue collected at the i position by doing : sums[i] - (n-i)*v[i], here v[] is the array containing strengths of the teams. For example, lets take the following case :

4

3 10 3 5

Here, sums[0] = 3 + 10 + 3 + 5, sums[1] = 10 + 3 + 5, sums[2] = 3 + 5, sums[3] = 5 and sums[4] = 0. So, if we do (sums[i] - (n-i)*v[i]) for every i>0 and <n, we should get the right answer. Here is the calculation :

sums[1] - (4-1)*3 = 9

Read more… (179 words)

comment in this discussion

Guys, for some reason this code is giving me wrong answers. I've used the standard memoization approach but it still won't work. Any help would be appreciated!

#include <iostream>#include <algorithm>#include <string.h>#include <limits>using namespace std;#define FR(a) for(int i=0;i<(a);i++)#define FR1(a) for(int i=1;i<(a);i++)#define FRE(a) for(int i=0;i<=(a);i++)#define FR1E(a) for(int i=1;i<=(a);i++)#define FRC(a,b) for(int i=(a);i<(b);i++)#define FRCE(a,b) for(int i=(a);i<=(b);i++)int dp[200001][6];int nv[200001];int n;int sv(int ind,int d)

Read more… (27 words)