This SRM was scheduled for 5:30 pm IST. I was at office then. This time my approach was different. I first approached for DIV-II 250. I was able to successfully submit the code at 240 points. Then I opened 500 points problem. This time 500 points was relatively easy. I was able to submit at 431 points. This ascended me to within 70 ranks in DIV-II (after 25 minutes of SRM starting). I had sufficient time to approach for 1000 points. I opened it, problem was awesome. I thought it in DP + Maths way. After 25 minutes of opening 1000 points , I felt like I cannot do it.
System test results: Both 250 and 500 passed. I couldn’t solve 1000 pointer(i had no idea how to solve during contest). Finally I finished at 113th position in DIV-II among 1350 coders. This time again I ascended to DIV-I.
Let’s discuss the 1000 pointer problem (250 and 500 pointer were simply brute force) :
1000 pointer problem (DIV-II)
http://community.topcoder.com/stat?c=problem_statement&pm=11802&rd=14728&rm=311958&cr=22938770
You can refer the problem from here(p.s. due to copyright issue I am not publishing it’s contents)
The Java implementation of the above problem is :
double[][] DP = new double[55][55]; public static int INF = Integer.MAX_VALUE; public double findMaximum(int[] revenues, int k) { Arrays.sort(revenues); double ans = -INF; for(int i = 0; i <= revenues.length; i++) { for(int j = 0; j <= revenues.length; j++) { DP[i][j] = ans; } } DP[0][0] = 0; for(int i = 1; i <= revenues.length; i++) { for(int j = 1; j <= revenues.length; j++) { int cnt = 0; double sum = DP[i - 1][j - 1]; if(i - 1 != 0) cnt++; for(int m = i; m <= revenues.length; m++) { cnt++; sum += revenues[m - 1]; if(cnt >= k) DP[m][j] = Math.max(DP[m][j], 1.*sum / cnt); } } } for(int i = 1; i <= revenues.length; i++) ans = Math.max(DP[revenues.length][i], ans); return ans; }