Has anybody solved these two? If so, how?

Hey,

Oddsort is a tricky problem. Note that a certain subsequence of numbers would not be moved at all, and the rest would be moved relative to it. Once youâ€™ve thought this far, the solution is easy. Two observations â€” the subsequence that is fixed has to be in an increasing order. Secondly, the optimal solution is achieved when the sum of this subsequence is maximum. You can also prove this somewhat informally.

Ants is actually a problem from a SRM (446), namely AntsOnGraph. The solution is available at http://apps.topcoder.com/wiki/display/tc/SRM+446.

Cheers,

Shikhin

Thanks for your help. The topcoder link doesnâ€™t seem to work though. I logged in but the server failed with a null pointer exceptionâ€¦ If it works for you, could you take a screenshot/ paste the text somewhere? Edit: nevermind, I got it, nice problem with an interesting solution.

Indeed. In fact, after solving that, I found a few more interesting problems that relied on fun uses of the exponentiation by squaring idea for efficient solutions. Cheers!

Care to share them?

It seems that huge numbers are a giveaway for this sort of thing.

Hey,

I have solved the ODDSORT Problem. Its pretty easyâ€¦ Hereâ€™s my C++ Source Codeâ€¦I got a 100:

#include â€śiostreamâ€ť

#include â€śalgorithmâ€ť

using namespace std;

int main()

{

```
int n, sum=0;
cin >> n;
int x[n+1], y[n+1];
for (int i = 1; i<=n; i++)
{
cin >> x[i];
y[i]=x[i];
sum+=x[i];
}
sort (y+1, y+n+1);
int mf[n+1][n+1];
for (int j = 0; j<=n; j++)
{
mf[j][0]=0;
mf[0][j]=0;
}
for (int p = 1; p<=n; p++)
for (int q = 1; q<=n; q++)
{
if (x[p]==y[q])
mf[p][q]=x[p]+mf[p-1][q-1];
else
mf[p][q]=max(mf[p-1][q], mf[p][q-1]);
}
sum-=mf[n][n];
cout << sum;
return 0;
```

}

I read ANTâ€™s prob. statement and I think I can solve that alsoâ€¦Please wait for no more than 3 hours!!! Iâ€™ll upload the solutionâ€¦

No worries (or hurry), as you can see Iâ€™ve already got the solution from idraumr. (got both accepted as well)

A repeated operation to be performed for a specific large number of times seems to be the â€śgistâ€ť of it.

ok @superty!!! I was jst about to upload my source codeâ€¦

and u dont hv to stress on the word HURRY every time!!!

@idraumr @superty although a complexity of O(N^2) is enough for the ODDSORT problem, do you know an algorithm with an O(NlogN) or O(N) complexity?

There is an official solution available. Click on statement and download the attached .cpp file.