bzoj3442 Study Group

Source: Internet
Author: User

Currently in the fan's tle state

3442: Study Group time limit:5 Sec Memory limit:128 MB
submit:200 solved:87
Description "Background" hang school is ready to encourage students to participate in study groups. "description" A total of n students, m study groups, each student has a certain preference, only willing to participate in some of the study groups, but the school leadership for the students to consider, a maximum number of students to participate in the K Study Group. The finance department's uncle is not so good, he wants to collect the money as much as possible, because each student attends the study group to pay the certain commission fee, the different study group has the different Commission fee. However, it backfired, the school leadership also decided to reward the study group organizers, if a student to participate in the first Study group, then to the study group organizers to reward ci*a^2 yuan. Ask the Finance department to spend at least how much (if negative, the negative output) (the total reward fee-the total fee) of the participating students (not the sum of the number of each study group) as much as possible. Input has several rows, and the first line has three positive integers separated by spaces N, M, K. The next line has a M positive integer representing each CI. The third line has m positive integers, indicating the fee fi required to attend each study group. Then there is an N-row m-column matrix, the table if the number of row J of line I is 1, then the first student is willing to participate in the J Study Group, if 0, is unwilling. Output outputs have only one integer, which is the minimum expense. Sample Input
3 3 1
1 2 3
3 2 1
111
111
111
Sample Output
-2
"Sample Interpretation"
The maximum number of participants is 3, each student participates in a study group, if two students attend the first Study group, one student participates in the second Study Group (must have someone to attend a second study group), expenditure is 2, can prove that there is no better plan.
"Data scope and conventions"
100% of the data, 0 HINT Source

by lll6924 at "Winter Camp after the race to relax"

1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <queue>8 using namespacestd;9 Const intinf=100000000;Ten Const intmxn= Max; One intn,m,k; A intC[MXN]; - intF[MXN]; - intans=0; the //Net - structedge{ -     int  from, To,nx,v,c; -}e[mxn* -]; + ints,t; - intCnt=1; + intHD[MXN],DIS[MXN],PR[MXN]; A BOOLINQU[MXN]; at // - voidAdd_edge (intUintTintVintc) { -E[++cnt]= (Edge) {u,t,hd[u],v,c};hd[u]=CNT; -E[++cnt]= (Edge) {t,u,hd[t],0,-c};hd[t]=CNT; -     return ; - }  in BOOLSPFA () { -     inti,j; toqueue<int>Q; +memset (Inqu,false,sizeof(Inqu)); -      for(i=0; i<=t;i++) dis[i]=INF; thedis[s]=0; * Q.push (s); $inqu[s]=true;Panax Notoginseng      while(!Q.empty ()) { -         intu=Q.front (); theinqu[u]=false; + Q.pop (); A          for(i=hd[u];i;i=e[i].nx) { the             intv=e[i].to; +             if(E[I].V && dis[u]+e[i].c<Dis[v]) { -dis[v]=dis[u]+e[i].c; $pr[v]=i; $                 if(!Inqu[v]) { -inqu[v]=true; - Q.push (v); the                 } -             }Wuyi         } the     } -     returndis[t]!=INF; Wu } - voidmcf () { About     inti,j; $      while(SPFA ()) { -         inttmp=INF; -          for(I=pr[t];i;i=pr[e[i]. from]) -tmp=min (tmp,e[i].v); Aans+=tmp*Dis[t]; +          for(I=pr[t];i;i=pr[e[i]. from]){ thee[i].v-=tmp; -e[i^1].v+=tmp; $         } the     } the     return; the } the intMain () { -scanf"%d%d%d",&n,&m,&k); in     inti,j; the      for(i=1; i<=m;i++) scanf ("%d",&c[i]); the      for(i=1; i<=m;i++) scanf ("%d",&f[i]); About     Charch[ -]; the      for(i=1; i<=n;i++){ thescanf"%s", ch); the          for(j=1; j<=m;j++){ +             if(ch[j-1]=='1') Add_edge (I,j+n,1,0); -         } the     }Bayis=0; t=n+m+1; the      for(i=1; i<=n;i++){ theAdd_edge (S,i,k,0); -Add_edge (i,t,k-1,0);//Set aside the empty side (not everyone has to fill the class) -     } the      for(i=1; i<=m;i++) the        for(j=1; j<=n;j++){ theAdd_edge (I+n,t,1,(2*j-1) *c[i]-f[i]); the         //split the edge, every one more people to the class, spending growth -       } the MCF (); theprintf"%d\n", ans); the     return 0;94}

bzoj3442 Study Group

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.