#define UW (!strcmp(argv[0]+strlen(argv[0])-4,".cmd")) #define WRONG (UW?1:2) #define FORMAT (UW?2:1) #define OK 0 #include #include #define SIZE 100 char g[SIZE][SIZE]; int i,j,k,m,n,p,x,a,size; int v[SIZE], cnt[SIZE][SIZE], is, best[SIZE][SIZE], prev[SIZE][SIZE]; dump(int p, int x){ if (p) dump(p-1,prev[p][x]); printf(" %d",x+1); } main(int argc, char **argv){ FILE *d; if (UW) { char tmp[1000]; strcpy(tmp,argv[0]); strcpy(tmp+strlen(tmp)-3,"dat"); d = fopen(tmp,"r"); strcpy(tmp+strlen(tmp)-3,"diff.sample"); } else { d = fopen(argv[1],"r"); } while (1 == fscanf(d,"%d",&n) && n != -1) { memset(g,0,sizeof(g)); memset(cnt,0,sizeof(cnt)); for (i=0;i0;j--) { for (i=0;i best[n+1][j]) { best[n+1][j] = cnt[i][j] + best[n][i]; prev[n+1][j] = i; } } } } //printf("%d",p+1); //dump(p,SIZE-1); //printf("\n"); printf("Best solution: %d\n",best[p][SIZE-1]); { int i, cA, csol[101], cbest=0; scanf("%d",&cA); if (cA != p+1) { printf("contest can't get the size right!!\n"); exit(WRONG); } for (i=0;i= csol[i+1]) { printf("streets not in ascending order: %d %d\n",csol[i],csol[i+1]); exit(WRONG); } cbest += cnt[csol[i]-1][csol[i+1]-1]; } printf("Contestant says: %d\n",cbest); if (cbest != best[p][SIZE-1]) { printf("mismatch!\n"); exit(WRONG); } } } if (n != -1) printf("missing end delimiter\n"); printf("Judge says OK\n"); exit(OK); }