Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

囧……

Posted by yc5_yc at 2012-09-01 21:11:28 on Problem 1698
Dinic中的level的数量算小了,愣是没发现,WA*N
#include <cstdio>
#include <string.h>
using namespace std;
const int NMax=55;
struct edge {
    int num,len;
    edge *next,*rev;
}*A[1000],pool[30000];
int N,nn,L,D[NMax],W[NMax];
bool F[NMax][8];
void Build(int x,int y,int z) {
    edge *p=&pool[L++],*q=&pool[L++];
    p->num=y;p->len=z;p->next=A[x];A[x]=p;p->rev=q;
    q->num=x;q->len=0;q->next=A[y];A[y]=q;q->rev=p;
}
int q[1000],level[1000];
bool makelevel() {
    for(int i=1;i<=nn;i++) level[i]=-1; 
    q[0]=0;level[0]=0;
    for(int i=0,bot=1;i<bot;i++) {
        int tmp=q[i];
        for(edge *p=A[tmp];p;p=p->next) if(p->len && level[p->num]==-1)
            level[q[bot++]=p->num]=level[tmp]+1;
    }
    return level[nn]!=-1;
}
inline int min(int a,int b) {return a<b?a:b;}
int Find(int a,int alpha) {
    if(a==nn) return alpha;
    int tot=0,tmp;
    for(edge *p=A[a];p && tot<alpha;p=p->next) {
        if(p->len && level[p->num]==level[a]+1)
            if(tmp=Find(p->num,min(p->len,alpha-tot))) {
                tot+=tmp;
                p->len-=tmp;
                p->rev->len+=tmp;
            }
    }
    if(!tot) level[a]=-1;
    return tot;
} 
int main()
{
    int T,WMax;
    scanf("%d",&T);
    while(T--) {
        L=0;memset(A,0,sizeof(A));
        scanf("%d",&N);
        WMax=0;
        int tot=0;
        for(int i=1;i<=N;i++) {
            for(int j=1;j<=7;j++) scanf("%d",&F[i][j]);
            scanf("%d%d",&D[i],&W[i]); tot+=D[i];
            if(W[i]>WMax) WMax=W[i]; 
        }
        nn=N+7*WMax+1;
        for(int i=1;i<=N;i++) {
            Build(0,i,D[i]);
            for(int j=1;j<=W[i];j++)for(int k=1;k<=7;k++) if(F[i][k])Build(i,N+(j-1)*7+k,1);
        }
        for(int i=1;i<=7*WMax;i++) Build(N+i,nn,1);
        int ret=0,tmp;
        while(makelevel()) 
            while(tmp=Find(0,100000000)) ret+=tmp;
        //printf("%d\n",ret);
        puts(ret>=tot?"Yes":"No");
    }  
    getchar();getchar();
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator