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...或者好心的帮忙看下代码吧。。。改的都晕了 #include <cstdio> #include <string.h> int ans,visit[110],q[1000],pre[110],nn[110][110],mm[110][110],c[51][100][100],flow[110][110],dis[110],n,m,k,kk; int oo=10000; int spfa(int s,int t) { int i,d,h,u; for (i=0;i<=109;++i) pre[i]=-1,visit[i]=0,dis[i]=oo; h=0;d=1;q[1]=s;dis[s]=0; visit[s]=1; while (h<d) { ++h; u=q[h]; for (i=0;i<=n+m+1;++i) if (flow[u][i]>0&&dis[u]+c[kk][u][i]<dis[i]) { dis[i]=dis[u]+c[kk][u][i]; pre[i]=u; if (visit[i]==0) { ++d; q[d]=i; visit[i]=1; } } visit[u]=0; } return dis[n+m+1]; } int get(int s,int t) { int mc,u,v; mc=oo; for (u=t;u!=s;) { v=u;u=pre[u]; if (flow[u][v]<mc) mc=flow[u][v]; } for (u=t;u!=s;) { v=u;u=pre[u]; flow[u][v]-=mc; flow[v][u]+=mc; } return mc*dis[n+m+1]; } int getmincost() { int offer=0,need=0,i,j; for (i=1;i<=m;++i) offer+=mm[i][k]; for (i=1;i<=n;++i) need+=nn[i][k]; if (offer<need) return -1; ans=0; for (kk=1;kk<=k;++kk) { memset(flow,0,sizeof(flow)); for (i=1;i<=n;++i) flow[i][n+m+1]=nn[i][kk]; for (i=n+1;i<=n+m;++i) flow[0][i]=mm[i-n][kk]; for (i=1;i<=n;++i) for (j=1;j<=m;++j) flow[j+n][i]=1000; while (spfa(0,n+m+1)!=oo) ans+=get(0,n+m+1); } return ans; } int main() { int i,j; for(;;) { scanf("%d%d%d",&n,&m,&k); if (n+m+k==0) return 0; for (i=1;i<=n;++i) for (j=1;j<=k;++j) scanf("%d",&nn[i][j]); for (i=1;i<=m;++i) for (j=1;j<=k;++j) scanf("%d",&mm[i][j]); memset(c,0,sizeof(c)); for (kk=1;kk<=k;++kk) for (i=1;i<=n;++i) for (j=1;j<=m;++j) { scanf("%d",&c[kk][j+n][i]); c[kk][i][j+n]=-c[kk][j+n][i]; } printf("%d\n",getmincost()); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator