工作分配问题

来源:互联网 发布:bindvalue数组 编辑:程序博客网 时间:2024/05/18 01:30
#include<iostream>using namespace std;int n,cost=0;int x[15],c[15][15];void work(int i,int count){    if(i>n && count<cost){      cost = count;      return ;    }    if(count<cost)      for(int j=1;j<=n;j++)        if(x[j] == 0){            x[j] = 1;            work(i+1,count+c[i][j]);            x[j] = 0;           }}int main(){    cin>>n;    for(int i=1;i<=n;i++){      for(int j=1;j<=n;j++){        cin>>c[i][j];        x[j] = 0;        }      cost+=c[i][i];      }    work(1,0);    cout<<cost<<endl;    return 0;}


 

原创粉丝点击