2403: Simple Problem Again

2403: Simple Problem Again


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K530106Standard

Everyone knows WeiXiaobao has seven wives. He is happy, but also has a lot of trouble.

He has a 7*7 plots of land,and he want to built seven houses for his wifes in his 49 small lands.Each row and coloum cannot have more than one house.(We know women like to feel jealous.) Different plots have different construction costs.He wanted to know how to build houses can let the money spent at most.(because he loves his wifes ,and believes that the more expensive the houses is ,the less trouble will be.)

Mars is an outstanding mathematician,and also is a friend of WeiXiaobao.After solved Weixiaobao's difficulty,he thought, if WeiXiaobao had n wives, and had n*n plots of land. How he should solve this problem .

 

Input

The first line has a positive number n(n<14).then followed n rows, each row has n positive integer(<300).The i+1 line j number represent the cost in (i,j).

Output

For each input data ouput the max cost.

Sample Input

3

1 2 3
3 2 1
2 3 2

Sample Output

9

Hint: he should build his houses in (1,3),(2,1),(3,2).

 

Problem Source: provided by AC2006

 


This problem is used for contest: 85 

 

#include<stdio.h>
#include<string.h>
int n,max;
int map[14][14],b[14];
bool f[14];
void dfs(int depth,int nowcost)
{
int i;
if(depth>n)
{
if(nowcost>max) max=nowcost;
return;
}
if(nowcost+b[n]-b[depth-1]<max) return;
    for(i=1;i<=n;i++)
    if(!f[i])
    {
f[i]=true;
dfs(depth+1,nowcost+map[depth][i]);
f[i]=false;
}
}
int main()
{
int i,j;
while(scanf("%d",&n)!=EOF)
{
memset(f,false,sizeof(f));
memset(b,0,sizeof(b));
for(i=1;i<=n;i++)
{
  max=0;
  for(j=1;j<=n;j++)
  {
    scanf("%d",&map[i][j]);
    if(max<map[i][j]) max=map[i][j];
  }
  if(i==1) b[i]=max;
   else  b[i]=b[i-1]+max;
}
max=0;
dfs(1,0);
printf("%d/n",max);
}
return 0;
}
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值