/* * @(#) msu98_c.c - Problem 'C' ("Parliament") solution * of the ACM Programming Contest at the MSU in 1998. * (c) 1998 Ivan Maidanski http://ivmai.chat.ru * Freeware program source. All rights reserved. ** * Language: ANSI C * Tested with: Borland C++ v3.1 * Last modified: 1998-10-07 20:45:00 GMT+04:00 */ /* Input data file: c.dat */ #include /* malloc(), free() */ #include /* FILE, fopen(), fscanf(), printf() */ #define N 1000 int k[N]; float p[N]; float *q,*r; int main() { FILE *f=fopen("c.dat","rt"); int t,curt; int x,m,n; float p0,s; int i,j; fscanf(f,"%*[^-0-9]%d",&t); for (curt=1;curt<=t;curt++) { fscanf(f,"%*[^-0-9]%d%*[^-0-9]%d%*[^-0-9]%d",&x,&m,&n); for (i=0,s=0;i=0) { q=(float *)malloc((x+1)*sizeof(float)); r=(float *)malloc((x+1)*sizeof(float)); for (j=0;j<=x;j++) q[j]=s; for (i=0;i=k[i] && q[j-k[i]]+p[i]>q[j])? q[j-k[i]]+p[i] : q[j]; for (j=0;j<=x;j++) q[j]=r[j]; } free((void *)r); for (j=0;j