日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[BZOJ3698] XWW的难题 网络流

發布時間:2023/12/20 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [BZOJ3698] XWW的难题 网络流 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

3698: XWW的難題

Time Limit:?10 Sec??Memory Limit:?128 MB
Submit:?533??Solved:?275
[Submit][Status][Discuss]

Description

XWW是個影響力很大的人,他有很多的追隨者。這些追隨者都想要加入XWW教成為XWW的教徒。但是這并不容易,需要通過XWW的考核。
XWW給你出了這么一個難題:XWW給你一個N*N的正實數矩陣A,滿足XWW性。
稱一個N*N的矩陣滿足XWW性當且僅當:(1)A[N][N]=0;(2)矩陣中每行的最后一個元素等于該行前N-1個數的和;(3)矩陣中每列的最后一個元素等于該列前N-1個數的和。
現在你要給A中的數進行取整操作(可以是上取整或者下取整),使得最后的A矩陣仍然滿足XWW性。同時XWW還要求A中的元素之和盡量大。

Input

第一行一個整數N,N ≤ 100。
接下來N行每行包含N個絕對值小于等于1000的實數,最多一位小數。

Output

輸出一行,即取整后A矩陣的元素之和的最大值。無解輸出No。

Sample Input

4
3.1 6.8 7.3 17.2
9.6 2.4 0.7 12.7
3.6 1.2 6.5 11.3
16.3 10.4 14.5 0

Sample Output

129

HINT

?

【數據規模與約定】

有10組數據,n的大小分別為10,20,30...100。

【樣例說明】

樣例中取整后滿足XWW性的和最大的矩陣為:

3 7 8 18

10 3 0 13

4 1 7 12

17 11 15 0


?

?

Source

?

n行n列分別看成n個點,s為源點,t為匯點.
s向每一行i連(l[i][n],r[i][n])的邊.
每一列i向t連(l[n][i],r[i][n])的邊.
每一行i向每一行j連(l[i][j],r[i][j])的邊.
求有源有匯有上下界的最大流.
最后答案要乘3.

?

1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<cstdlib> 6 #include<cmath> 7 using namespace std; 8 int n; 9 double a[105][105]; 10 int l[105][105],r[105][105]; 11 int s=0,t=999,S=1000,T=1001; 12 int q[10005],dis[10005]; 13 struct edge { 14 int to,next,f; 15 }e[80050]; 16 int head[10000],cnt; 17 void add(int u,int v,int w) { 18 e[cnt].to=v;e[cnt].next=head[u];e[cnt].f=w;head[u]=cnt++; 19 e[cnt].to=u;e[cnt].next=head[v];e[cnt].f=0;head[v]=cnt++; 20 } 21 bool bfs() { 22 memset(dis,-57,sizeof(dis)); 23 int h=0,tail=1; 24 q[h]=T; 25 dis[T]=0; 26 while(h!=tail) { 27 int now=q[h++];if(h==10000) h=0; 28 for(int i=head[now];i>=0;i=e[i].next) { 29 if(dis[e[i].to]>-100000||!e[i^1].f) continue; 30 dis[e[i].to]=dis[now]-1; 31 q[tail++]=e[i].to;if(tail==10000) tail=0; 32 } 33 } 34 return dis[S]>=-100000; 35 } 36 int dfs(int now,int a) { 37 int f=0,flow=0; 38 if(now==T) return a; 39 for(int i=head[now];i>=0;i=e[i].next) { 40 int to=e[i].to; 41 if(dis[to]==dis[now]+1&&e[i].f>0) { 42 f=dfs(to,min(a,e[i].f)); 43 flow+=f; 44 e[i].f-=f; 45 e[i^1].f+=f; 46 a-=f; 47 if(a==0) break; 48 } 49 } 50 return flow; 51 } 52 int dinic() { 53 int ans=0; 54 while(bfs()) {ans+=dfs(S,2147483647);} 55 return ans; 56 } 57 int main() { 58 memset(head,-1,sizeof(head)); 59 scanf("%d",&n); 60 for(int i=1;i<=n;i++) 61 for(int j=1;j<=n;j++) { 62 scanf("%lf",&a[i][j]); 63 l[i][j]=(int)a[i][j]; 64 if(a[i][j]==l[i][j]) r[i][j]=l[i][j]; 65 else r[i][j]=l[i][j]+1; 66 } 67 add(t,s,214748364); 68 int sum=0; 69 for(int i=1;i<n;i++) {add(S,i,l[i][n]);add(s,i,r[i][n]-l[i][n]);add(s,T,l[i][n]);sum+=l[i][n];} 70 for(int i=1;i<n;i++) {add(i+n,T,l[n][i]);add(i+n,t,r[n][i]-l[n][i]);add(S,t,l[n][i]);sum+=l[n][i];} 71 for(int i=1;i<=n-1;i++) { 72 for(int j=1;j<=n-1;j++) {add(S,j+n,l[i][j]);add(i,T,l[i][j]);add(i,j+n,r[i][j]-l[i][j]);sum+=l[i][j];} 73 } 74 if(dinic()==sum) { 75 S=s,T=t; 76 printf("%d\n",dinic()*3); 77 } 78 else printf("No\n"); 79 } 80 /* 81 82 */ View Code

?

轉載于:https://www.cnblogs.com/wls001/p/8516145.html

總結

以上是生活随笔為你收集整理的[BZOJ3698] XWW的难题 网络流的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。