hdu1498匈牙利演算法/最小點覆蓋

來源:互聯網
上載者:User

http://acm.hdu.edu.cn/showproblem.php?pid=1498

剛開始題目沒理解汗~~

將橫座標作為x集合縱座標為y集合 每個顏色的座標組應一條邊,求最小點(橫或縱,即為需要射擊的次數)覆蓋對應邊的個數,

代碼:

/*************************************************************************> File Name: main.cpp> Author: huangshuai> Mail: huangshuai1993@gmail.com > Created Time: Sat 09 Mar 2013 02:00:24 PM CST ************************************************************************/#include<iostream>#include<cstring>#include<queue>#include<cstdio>using namespace std;int map[55][105][105];int vis[105];int link1[105];int n;int dfs(int i,int j){int l;for(l=1;l<=n;l++){if(!vis[l]&&map[i][j][l]){vis[l]=1;if(link1[l]==-1||dfs(i,link1[l])){link1[l]=j;return 1;}}}return 0;}int main(){int k;int i,j;while(scanf("%d%d",&n,&k)!=EOF){if(n==0&&k==0)break;memset(map,0,sizeof(map));int temp[55],o=0;memset(temp,0,sizeof(temp));for(i=1;i<=n;i++){for(j=1;j<=n;j++){int t;scanf("%d",&t);map[t][i][j]=1;temp[t]=1;}}queue<int> q;for(i=0;i<52;i++){if(!temp[i])continue;memset(link1,-1,sizeof(link1));int s=0;for(j=1;j<=n;j++){memset(vis,0,sizeof(vis));if(dfs(i,j))s++;}if(s>k)q.push(i);}if(q.empty())printf("-1\n");else{printf("%d",q.front());q.pop();while(!q.empty()){printf(" %d",q.front());q.pop();}printf("\n");}}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.