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 |
构图是重点,贴代码!!!#include<iostream> #include<queue> #define inf 99999999 using namespace std; int house[1005]; int last[1005]; int map[1005][1005]; int pre[1005]; int n,np,nc,m; queue<int>myque; bool bfs(int s,int t) { memset(pre,-1,sizeof(pre)); while (!myque.empty()) myque.pop(); pre[s]=0; int index; myque.push(s); while (!myque.empty()) { index=myque.front(); myque.pop(); for (int i=s;i<=t;i++) { if (pre[i]==-1&&map[index][i]>0) { pre[i]=index; if(i==t) return true; myque.push(i); } } } return false; } int Flow(int s,int t) { int maxflow=0; while (bfs(s,t)) { int minflow=inf; int i; for(i=t;i!=s;i=pre[i]) minflow=min(minflow,map[pre[i]][i]); for (i=t;i!=s;i=pre[i]) { map[pre[i]][i]-=minflow; map[i][pre[i]]+=minflow; } maxflow+=minflow; } return maxflow; } int main() { int cus_num,num,buy; int hou_num; int s,t,k; memset(map,0,sizeof(map)); memset(house,0,sizeof(house)); memset(last,0,sizeof(last)); cin>>hou_num>>cus_num; s=0;t=cus_num+1; for(int i=1;i<=hou_num;i++) { cin>>house[i]; } for(int i=1;i<=cus_num;i++) { cin>>num; for(int j=1;j<=num;j++) { cin>>k; if(last[k]==0) map[s][i]+=house[k]; else map[last[k]][i]=inf; last[k]=i; } cin>>buy; map[i][t]=buy; } cout<<Flow(s,t)<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator