2324: Go Dutch
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
10s | 8192K | 303 | 88 | Standard |
Input
Input consists of several test cases. The first line of each case is a positive interger N(2<=N<14), it is the number of persons (and jobs). The next N line include N integers, the cost of i-th person doing j-th job is the j-th element in line i.Output
For each input N, you should the minimum cost in one line.Sample Input
3 10 93 73 12 69 40 88 62 76
Sample Output
112
Problem Source: skywind
This problem is used for contest: 52
#include<stdio.h>
#include<string.h>
const int inf=(1<<31)-2;
//int a[15][15];
int val[15][15];
int flag[15];
int n;
int min;
void dfs(int x,int sum)
{
if(x==n) {if(sum<min) min=sum;return ;}
if(sum>=min) return ;
for(int i=0;i<n;i++)
{
if(flag[i]==0)
{
flag[i]=1;
dfs(x+1,sum+val[x][i]);
flag[i]=0;
}
}
}
int main()
{
int i,j;
while(scanf("%d",&n)==1)
{
memset(flag,0,sizeof(flag));
for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&val[i][j]);
min=inf;
dfs(0,0);
printf("%d/n",min);
}
return 0;
}