标签:nbsp LLC rip std into lis span names org
Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 747 Accepted Submission(s): 303
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second #define all(a) (a).begin(), (a).end() #define fillchar(a, x) memset(a, x, sizeof(a)) #define huan printf("\n") #define debug(a,b) cout<<a<<" "<<b<<" "<<endl #define ffread(a) fastIO::read(a) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN = 1000+10; const int MAXM = 500+10; int uN,vN; int g[MAXN][MAXM]; int linker[MAXM][MAXN]; bool used[MAXM]; int num[MAXM],limit; bool dfs(int u) { for(int v = 0; v < vN; v++) if(g[u][v] && !used[v]) { used[v] = true; if(linker[v][0] < limit) { linker[v][++linker[v][0]] = u; return true; } for(int i = 1; i <= linker[v][0]; i++) if(dfs(linker[v][i])) { linker[v][i] = u; return true; } } return false; } int hungary() { int res = 0,flag=0; for(int i = 0; i < vN; i++) linker[i][0] = 0; for(int u = 0; u < uN; u++) { memset(used,false,sizeof(used)); if(dfs(u)) res++; else { flag=1; break; } } return flag; } int main() { while(scanf("%d%d",&uN,&vN)!=EOF&&uN&&vN) { fillchar(g,0); getchar(); for(int i=0;i<uN;i++) { char s[2000]; gets(s); int len=strlen(s); int num=0,jishu=0; for(int j=len-1;j>=0;j--) { if(s[j]==‘ ‘) { g[i][num]=1; num=jishu=0; } else if(s[j]>=‘0‘&&s[j]<=‘9‘) { num+=(int)(s[j]-‘0‘)*pow(10,jishu); jishu++; } else break; } } int l=0,r=uN; while(l<=r) { limit=(l+r)/2; //cout<<limit<<endl; if(!hungary()) r=limit-1; else l=limit+1; } printf("%d\n",r+1); } }
标签:nbsp LLC rip std into lis span names org
原文地址:https://www.cnblogs.com/stranger-/p/9822440.html