/* * @(#) smt4.c - Program for solving distribution problem using Bradford * method (Task 4 (problem 802) at the Special Military Training course). * (c) 1998 Ivan Maidanski http://ivmai.chat.ru * Freeware program source. All rights reserved. ** * Language: ANSI C * Tested with: Watcom C compiler v11.0 * Last modified: 1998-03-16 18:10:00 GMT+03:00 */ #include /* scanf(), printf() */ #define MAXN 20 int p[MAXN][MAXN],q[MAXN][MAXN]; int x[MAXN][MAXN]; void swap(int *a, int *b) { int t=*a; *a=*b; *b=t; } void transp_matr(int a[MAXN][MAXN], int n, int m) { int j; if (m>n) n=m; while (--n) for (j=n;j--;) swap(&a[n][j],&a[j][n]); } int sum_matr(int a[MAXN][MAXN], int x[MAXN][MAXN], int n, int m) { int j,z=0; while (n--) for (j=m;j--;) if (x[n][j]) z+=a[n][j]; return z; } void input_matr(int a[MAXN][MAXN], int n, int m) { int i,j; for (i=0;i=0) iter_dec(a,x,n,m,col); } int main(void) { int n,m; scanf("%d%d",&n,&m); input_matr(p,n,m); copy_matr(q,p,n,m); if (n>m) { transp_matr(q,n,m); find_cond_max(q,x,m,n); transp_matr(x,m,n); } else find_cond_max(q,x,n,m); print_matr(p,n,m); print_nonzero(x,n,m); printf("Z=%d\n\n",sum_matr(p,x,n,m)); return 0; }