Hi,
I tried solving the PARTY problem in JAVA first. I used dynamic programming to do and I kept getting NZEC even though the test cases on the page and the forum all passed. So i wrote the program in C++ and now I am getting WA. Can anyone please help me with this?
Thanks
#include<stdio.h>
#include<stdlib.h>
#define MAX_PARTIES 101
#define MAX_BUDGET 501
int max(int a, int b) {
if(a>=b) {
return a;
} else {
return b;
}
}
int min(int a, int b) {
if(a<=b) {
return a;
} else {
return b;
}
}
int main() {
int partyBudget, partyCount;
int currentParty;
int currentFun;
scanf("%d %d",&partyBudget,&partyCount);
int V[MAX_PARTIES][MAX_BUDGET] = {0};
int B[MAX_PARTIES][MAX_BUDGET] = {0};
while(partyBudget!=0 && partyCount!=0) {
int *partyEntrance, *partyFun;
partyEntrance = (int*) calloc(partyCount,sizeof(int));
partyFun = (int*) calloc(partyCount,sizeof(int));
for(int i=0; i<partyCount; i++) {
scanf("%d%d",¤tParty,¤tFun);
if(currentParty >= 5 && currentParty <= 25 && currentFun >= 0 && currentFun <= 10)
{
partyEntrance[i] = currentParty;
partyFun[i] = currentFun;
} else {
partyEntrance[i] = 0;
partyFun[i] = 0;
}
}
//actual problem solving
for(int i=0;i<partyCount+1;i++) {
for(int j=1;j<=partyBudget;j++) {
if(j>=partyEntrance[i-1]) {
V[i][j] = max(V[i-1][j],V[i-1][j-partyEntrance[i-1]] + partyFun[i-1]);
if(V[i][j] == V[i-1][j]) {
B[i][j] = B[i-1][j];
} else {
B[i][j] = B[i-1][j-partyEntrance[i-1]] + partyEntrance[i-1];
}
} else {
V[i][j] = V[i-1][j];
B[i][j] = B[i-1][j];
}
}
}
printf("%d %d\n",B[partyCount][partyBudget], V[partyCount][partyBudget]);
for(int i=0;i<=partyCount;i++) {
for(int j=0;j<=partyBudget;j++) {
V[i][j] = 0;
B[i][j] = 0;
}
}
free(partyEntrance);
free(partyFun);
scanf("%d %d", &partyBudget, &partyCount);
}
}