Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
先WA了几次都不过,后来加了一个贪心(aPath),其他的都没动就过了,为什么?#include <iostream.h> #include <string.h> #include <limits.h> #define Max 400 struct node { bool mark,check; int parse,min; }g[Max]; int n,k,c[Max][Max],a[Max][Max]; bool FindLink(); void Extend(); void aPath(); int MaxFlow() { int i,sum; memset(a,0,sizeof(a)); aPath(); while(FindLink()) Extend(); for(i=1,sum=0;i<=n;i++) sum+=a[i][n+1]; return sum; } void aPath() { int i,j; for(i=2;i<=k+1;i++) for(j=k+2;j<n;j++) { if(a[j][n]>=1 || c[i][j]==0) continue; a[i][j]++; a[j][n]++; a[n][n+1]++; a[1][i]++; if(a[1][i]>=c[1][i]) break; } } bool FindLink() { int i,x; for(i=0;i<=n+1;i++) g[i].mark=g[i].check=false; x=0;g[0].mark=true;g[0].min=INT_MAX; while(x<=n+1) { for(i=0;i<=n+1;i++) { if(!g[i].mark&&a[x][i]<c[x][i]) { g[i].mark=true;g[i].parse=x; g[i].min=( (g[x].min<c[x][i]-a[x][i])?g[x].min:(c[x][i]-a[x][i]) ); if(i==n+1) return true; } } for(i=0;i<=n+1;i++) { if(!g[i].mark&&a[i][x]>0) { g[i].mark=true;g[i].parse=-x; g[i].min=( (g[x].min<a[i][x])?g[x].min:a[i][x] ); if(i==n+1) return true; } } g[x].check=true; for(x=0;x<=n+1;x++) if(g[x].mark&&!g[x].check) break; } return false; } void Extend() { int i,j; int min=g[n+1].min; for(i=n+1;i>0;i=j) { if(g[i].parse>=0) { j=g[i].parse;a[j][i]+=min; } else { j=-g[i].parse;a[j][i]-=min; } } } int main() { int i,j,t,d,w,max,tl; int f[8]; cin>>t; while(t--) { cin>>k; max=0;tl=0; memset(c,0,sizeof(c)); c[0][1]=INT_MAX; for(i=2;i<=k+1;i++) { for(j=1;j<8;j++) cin>>f[j]; cin>>d>>w; c[1][i]=d; tl+=d; if(w>max) max=w; for(j=0;j<w;j++) for(int l=1;l<8;l++) if(f[l]) c[i][j*7+k+1+l]+=1; } n = max*7+k+2; for(i=k+2;i<n;i++) c[i][n]=1; c[n][n+1]=INT_MAX; if(MaxFlow()>=tl) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator