-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssignment_Problem.c
More file actions
47 lines (47 loc) · 790 Bytes
/
Assignment_Problem.c
File metadata and controls
47 lines (47 loc) · 790 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
void swap(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void permute(int a[], int l, int r,int arr[r+1][r+1],int *ans)
{
int i;
if (l == r)
{
int cost=0,t1;
for(int i=0;i<=r;i++)
{
t1=a[i];
cost+=arr[i][t1];
}
if(*ans>cost || *ans==0)
*ans=cost;
}
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
permute(a, l+1, r,arr,ans);
swap((a+l), (a+i));
}
}
}
int main()
{
int n,ans=0;
scanf("%d",&n);
int a[n],arr[n][n];
for(int i=0;i<n;i++)
a[i]=i;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
scanf("%d",&arr[i][j]);
}
permute(a,0,n-1,arr,&ans);
printf("%d",ans);
}