After finishing all the cakewalk DP problems on topcoder DIV-2 250 (lol they were just 3 :P) trying my hand at the DIV-2 500 DP Problems the problem attempted currently was :-srm 619 div 2 500
here a basic simulation of the problem was to be done with the key element being location of position to be erased for the elimination (it was (current_position+(i^3)-1)) :-
//The code
class ChooseTheBestOne
{
public:
int countNumber(int N) {
vector<int>dp(N,0);//create a vector<int> for employees
for(int i=0;i<N;i++)
{
dp[i]=i+1;//initialize the elements
}
long long int cp=0;//please note it is of 64 bit type
for(int i=1;dp.size()>1;i++)
{
cp=cp+pow(i,3)-1;
if(cp>dp.size()-1)
{
cp=cp%dp.size();
}
dp.erase(dp.begin()+cp);
}
return dp[0];
}
};
It didn't work the first time though because if you declare cp as integer type it would overflow it which was the fault with my solution in the beginning but a little bit of editorial glancing rectified it . Also a huge relief that end sems got over and the discrete maths paper was .... was.... let's just not talk about it :P but still one of my lab practicals remain. Anyways if you wanna check out the problem set i am attempting check out this link :- LINK DP PROBS DIV 2 500