2324: Go Dutch

2324: Go Dutch


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
10s8192K30388Standard
There are N person and N job to do. The i-th person do j-th job will cost different certain money. Choose a scheme that every person only do one different job, and total cost is minimum.

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;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值