比较简单的题……我一开始想成像软件开发那题一样的做法了……就是每天拆点,S->i (INF,0) 、i+n->T (u[i],0) 然后处理购入 S->i+n (INF,v[i]) 以及放置仓库 i->i+1 (s,m)、i->i+n+1 (s,m)
然后顺利WA了……没想通为什么……
实际上不用拆的,直接建就可以S->i (INF,d[i])、 i->T (u[i],0)、 i->i+1 (s,m) 就连这三种边就行了= =
1 /************************************************************** 2 Problem: 2424 3 User: Tunix 4 Language: C++ 5 Result: Accepted 6 Time:0 ms 7 Memory:7136 kb 8 ****************************************************************/ 9 10 //BZOJ 2424 11 #include<cmath> 12 #include<vector> 13 #include<cstdio> 14 #include<cstring> 15 #include<cstdlib> 16 #include<iostream> 17 #include<algorithm> 18 #define rep(i,n) for(int i=0;i<n;++i) 19 #define F(i,j,n) for(int i=j;i<=n;++i) 20 #define D(i,j,n) for(int i=j;i>=n;--i) 21 #define pb push_back 22 #define CC(a,b) memset(a,b,sizeof(a)) 23 using namespace std; 24 int getint(){ 25 int v=0,sign=1; char ch=getchar(); 26 while(!isdigit(ch)) {if(ch=='-') sign=-1; ch=getchar();} 27 while(isdigit(ch)) {v=v*10+ch-'0'; ch=getchar();} 28 return v*sign; 29 } 30 const int N=250,M=250000,INF=~0u>>2; 31 const double eps=1e-8; 32 /*******************template********************/ 33 int n,m,size,ans; 34 struct edge{int from,to,v,c;}; 35 struct Net{ 36 edge E[M]; 37 int head[N],next[M],cnt; 38 void ins(int x,int y,int z,int c){ 39 E[++cnt]=(edge){x,y,z,c}; 40 next[cnt]=head[x]; head[x]=cnt; 41 } 42 void add(int x,int y,int z,int c){ 43 ins(x,y,z,c); ins(y,x,0,-c); 44 } 45 int from[N],Q[M],d[N],S,T; 46 bool inq[N]; 47 bool spfa(){ 48 int l=0,r=-1; 49 F(i,1,T) d[i]=INF; 50 d[S]=0; Q[++r]=S; inq[S]=1; 51 while(l<=r){ 52 int x=Q[l++]; inq[x]=0; 53 for(int i=head[x];i;i=next[i]) 54 if(E[i].v && d[x]+E[i].c<d[E[i].to]){ 55 d[E[i].to]=d[x]+E[i].c; 56 from[E[i].to]=i; 57 if(!inq[E[i].to]){ 58 Q[++r]=E[i].to; 59 inq[E[i].to]=1; 60 } 61 } 62 } 63 return d[T]!=INF; 64 } 65 void mcf(){ 66 int x=INF; 67 for(int i=from[T];i;i=from[E[i].from]) 68 x=min(x,E[i].v); 69 for(int i=from[T];i;i=from[E[i].from]){ 70 E[i].v-=x; 71 E[i^1].v+=x; 72 } 73 ans+=x*d[T]; 74 } 75 void init(){ 76 n=getint(); m=getint(); size=getint(); 77 cnt=1; S=0; T=n+1; 78 int x; 79 F(i,1,n){ 80 x=getint(); 81 add(i,T,x,0); 82 } 83 F(i,1,n){ 84 x=getint(); 85 add(S,i,INF,x); 86 if (i<n) add(i,i+1,size,m); 87 } 88 while(spfa()) mcf(); 89 printf("%d\n",ans); 90 } 91 }G1; 92 int main(){ 93 #ifndef ONLINE_JUDGE 94 freopen("input.txt","r",stdin); 95 // freopen("output.txt","w",stdout); 96 #endif 97 G1.init(); 98 return 0; 99 }
2424: [HAOI2010]订货
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 572 Solved: 372
[Submit][Status][Discuss]
Description
Input
Output
只有1行,一个整数,代表最低成本
Sample Input
2 4 8
1 2 4
Sample Output
HINT
Source
http://www.lydsy.com/JudgeOnline/problem.php?id=2424