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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【POJ - 1698】Alice's Chance(网络流最大流,建图)

發(fā)布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【POJ - 1698】Alice's Chance(网络流最大流,建图) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start making the films at the same time, and the greedy Alice doesn't want to miss any of them!! You are asked to tell her whether she can act in all the films.?

As for a film,?

  • it will be made ONLY on some fixed days in a week, i.e., Alice can only work for the film on these days;?
  • Alice should work for it at least for specified number of days;?
  • the film MUST be finished before a prearranged deadline.

  • For example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice should work for the film at least for 4 days; and it must be finished within 3 weeks. In this case she can work for the film on Monday of the first week, on Monday and Saturday of the second week, and on Monday of the third week.?

    Notice that on a single day Alice can work on at most ONE film.?

    Input

    The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a single line containing an integer N (1 <= N <= 20), the number of films. Each of the following n lines is in the form of "F1 F2 F3 F4 F5 F6 F7 D W". Fi (1 <= i <= 7) is 1 or 0, representing whether the film can be made on the i-th day in a week (a week starts on Sunday): 1 means that the film can be made on this day, while 0 means the opposite. Both D (1 <= D <= 50) and W (1 <= W <= 50) are integers, and Alice should go to the film for D days and the film must be finished in W weeks.

    Output

    For each test case print a single line, 'Yes' if Alice can attend all the films, otherwise 'No'.

    Sample Input

    2 2 0 1 0 1 0 1 0 9 3 0 1 1 1 0 0 0 6 4 2 0 1 0 1 0 1 0 9 4 0 1 1 1 0 0 0 6 2

    Sample Output

    Yes No

    Hint

    A proper schedule for the first test case:date Sun Mon Tue Wed Thu Fri Satweek1 film1 film2 film1 film1week2 film1 film2 film1 film1week3 film1 film2 film1 film1week4 film2 film2 film2

    題目大意:

    alice接了N部電影的拍攝工作,所有電影在同一天開工。對于每個電影來說(第i個),每周只有固定幾天拍,且必須在周內(nèi)拍完,alice至少需要去拍天。問alice能否完成所有電影拍攝。alice每天只能去拍一部電影。

    解題報告:

    將電影也看做節(jié)點,將每一天看做一個節(jié)點,因為最多50周,所以最多350個節(jié)點。從源點出發(fā)流向每部電影,流量就是需要拍攝的天數(shù),從每部電影到拍攝周內(nèi)拍攝的那些天,流量是1,因為每天只能拍一部,同理這些天都連接到匯點,流量也是1,然后看源點能否滿流就可以了。

    AC代碼:

    #include<cstring> #include<cstdio> #include<algorithm> #include<iostream> using namespace std; int tot; struct Edge {int to,ne,w; } e[100005 * 2]; int head[10005]; int st,ed; int dis[10050],q[10005];//一共多少個點跑bfs,dis數(shù)組和q數(shù)組就開多大。 void add(int u,int v,int w) {e[++tot].to=v; e[tot].w=w; e[tot].ne=head[u]; head[u]=tot;e[++tot].to=u; e[tot].w=0; e[tot].ne=head[v]; head[v]=tot; } bool bfs(int st,int ed) {memset(dis,-1,sizeof(dis));int front=0,tail=0;q[tail++]=st;dis[st]=0;while(front<tail) {int cur = q[front];if(cur == ed) return 1;front++;for(int i = head[cur]; i!=-1; i = e[i].ne) {if(e[i].w&&dis[e[i].to]<0) {q[tail++]=e[i].to;dis[e[i].to]=dis[cur]+1;}}}if(dis[ed]==-1) return 0;return 1; } int dfs(int cur,int limit) {//limit為源點到這個點的路徑上的最小邊權(quán) if(limit==0||cur==ed) return limit;int w,flow=0;for(int i = head[cur]; i!=-1; i = e[i].ne) { if(e[i].w&&dis[e[i].to]==dis[cur]+1) {w=dfs(e[i].to,min(limit,e[i].w));e[i].w-=w;e[i^1].w+=w;flow+=w;limit-=w;if(limit==0) break;}}if(!flow) dis[cur]=-1;return flow; } int dinic() {int ans = 0;while(bfs(st,ed)) ans+=dfs(st,0x7fffffff);return ans; } int a[100005]; int main() {int t,n;cin>>t;while(t--) {tot=1;memset(head,-1,sizeof head);scanf("%d",&n);st=2000,ed=2001;//自己定就行了 for(int i = 101; i<=500; i++) /*add(i,i+1000,1),*/add(i,ed,1);//讓每一天的拆點連起來,并且把后置點和ed連起來 //其實上一步是不需要拆點的,因為每個點和終點只有一個連邊,所以不需要控制這個點只能被選擇一次。 但是拆不拆點都可以過。int ans = 0;for(int i = 1; i<=n; i++) {for(int j = 1; j<=9; j++) scanf("%d",a+j);add(st,i,a[8]);//我要給這個電影提供a[8]這么多天的流量。 ans += a[8];for(int j = 1; j<=7; j++) {if(a[j] == 0) continue;for(int k = 0; k<a[9]; k++) {//k=1,k<a[9]也可以? add(i,100+7*k+j,1);}}}int out = dinic();if(ans == out) printf("Yes\n");else printf("No\n"); }return 0 ; }

    ?

    總結(jié)

    以上是生活随笔為你收集整理的【POJ - 1698】Alice's Chance(网络流最大流,建图)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。