i will get max in c+1 categories using all possible combinations of c categories .
But how do i incorporate bonus point analysis. somebody please help me out with the algo of the problem.
i am stuck now.......
![:(](./images/smilies/icon_frown.gif)
Moderator: Board moderators
Code: Select all
int score(vector<int>& comb, int type) {
int sum = 0;
if (type < 6) {
for (int i = 0; i < 5; i++) {
if (comb[i] == type + 1)
sum += comb[i];
}
return sum;
}
switch (type) {
case 6:
for (int i = 0; i < 5; i++)
sum += comb[i];
break;
case 7:
for (int i = 0; i < 3; i++)
if (comb[i] == comb[i + 2]) {
sum = score(comb, 6);
}
break;
case 8:
for (int i = 0; i < 2; i++)
if (comb[i] == comb[i + 3]) {
sum = score(comb, 6);
}
break;
case 9:
if (comb[0] == comb[4]) {
sum = 50;
}
break;
case 10:
bool value[6];
memset(value, 0, sizeof(value));
for (int i = 0; i < 5; i++) {
value[comb[i] - 1] = 1;
}
for (int i = 0; i < 3; i++) {
if (value[i] && value[i + 1] && value[i + 2] && value[i + 3])
sum = 25;
}
break;
case 11:
memset(value, 0, sizeof(value));
for (int i = 0; i < 5; i++) {
value[comb[i] - 1] = 1;
}
for (int i = 0; i < 2; i++) {
if (value[i] && value[i + 1] && value[i + 2] && value[i + 3] && value[i + 4])
sum = 35;
}
break;
case 12:
if ((comb[0] == comb[1] && comb[2] == comb[4]) || (comb[0] == comb[2] && comb[3] == comb[4])) {
sum = 40;
}
break;
}
return sum;
}
I got AC using the Hungarian algorithm.jaken wrote:I've been getting WA for the past couple days playing with this, and I honestly am baffled as to the case(s) I'm missing. I've generated thousands of sample input games (~10k so far), ran them through the UVA Toolkit, and in every case my optimal score matched the toolkit's output. Typically I'll have about 150 games (per 1000) where my assignments are different from the toolkit's, but the total score is equivalent. (these should still pass, yes?) I've authored some hand-made input designed to catch edge cases and the results match too. (is the UVA toolkit authoritative?)
I'm about to start again using a dynamic programming approach, but wanted to share my current approach in case anyone sees a defect. Currently I'm using a mix of the Hungarian matching algorithm and backtrack search.
First I use the Hungarian matching to generate the optimal assignments (this matching doesnt consider the upper-bonus rule when maximizing the score). If this result does indeed yield the upper bonus, then I consider this matching to be optimal in any case, and I use it as my solution.
If the above matching does not yield the upper bonus I use Hungarian again to score the max in just the upper categories to see if the bonus is possible. If it is NOT then I consider the above matching to be my solution. If it IS then I use a backtrack search to generate all possible upper-category assignments such that we get the upper bonus. (typically < 2000 cases). For each of these I use Hungarian again to maximize the lower categories with the remaining rolls, and take as my solution that with the max score of all considered so far.
So like I said, I ran thousands of test games through the toolkit and havent had a miss yet. If anyone has any insight, please share!
Thanks
Code: Select all
1 2 3 4 5
2 2 3 4 5
3 3 1 1 1
5 5 5 5 5
6 6 6 6 6
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Code: Select all
1 4 3 4 25 30 15 0 0 0 25 35 40 35 217