void Potential int int int int int int Rez int a1 b1 int max im jm int

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void Potential(int M, int N, int *A, int *B, int **C, int **Rez)
{
int *u, *v,*a1,*b1,**x;
int i, j,k,max=0,im=0,jm=0;
u = (int*)malloc(M*sizeof(int));
v = (int*)malloc(N*sizeof(int));
x = (int**)malloc(M*sizeof(int*));
for (i = 1; i <= M; i++)
x[i] = (int*)malloc(N*sizeof(int));
u[1] = 0;
for (j = 1; j <= N; j++)
for (i = 1; i <= M; i++)
if (Rez[i][j] != 0)
{
v[j] = C[i][j] - u[i];
for (k = i + 1; k <= M; k++)
if (Rez[k][j] != 0)
u[k] = C[k][j] - v[j];
}
for (i = 1; i <= M; i++)
for (j = 1; j <= N; j++)
if (Rez[i][j] == 0)
{
x[i][j] = u[i] + v[j] - C[i][j];
cout « "x[" « i « "][" « j « "]=" « x[i][j] « "\n";
if (x[i][j] > 0 && x[i][j] > im)
{
max = x[i][j];
im = i;
jm = j;
}
}
}