description
假設乙個試題庫中有$n$道試題,每道試題都標明了所屬類別,同一道題可能有多個類別屬性。現要從題庫中抽取$m$道題組成試卷,並要求試卷包含指定型別的試題。求乙個滿足要求的組卷方案。
input
第$1$行有$2$個正整數$n,k,k$表示題庫中試題型別總數,$n$表示題庫中試題總數。
第$2$行有$k$個正整數,第$i$個正整數表示要選出的型別$i$的題數$a_i$。這$k$個數相加就是要選出的總題數$m$。
接下來的$n$行給出了題庫中每個試題的型別資訊。每行的第$1$個正整數$p$表明該題可以屬於$p$類,接著的$p$個數是該題所屬的型別號。
output
第$i$行輸出$"i:"$後接型別$i$的題號。如果有多個滿足要求的方案,只要輸出$1$個方案。
如果問題無解,則輸出「$no\;\;solution!$」
sample input
3 15
3 3 4
2 1 2
1 3
1 3
1 3
1 3
3 1 2 3
2 2 3
2 1 3
1 2
1 2
2 1 2
2 1 3
2 1 2
1 1
3 1 2 3
sample output
1: 1 6 8
2: 7 9 10
3: 2 3 4 5
hint
$2\;\leq\;k\;\leq\;20,k\;\leq\;n\;\leq\;1000$
solution
類別$i$為$x_i$,題$i$為$y_i$.
從$s$向$x_i$連線一條容量為$a_i$的有向邊,
從$x_i$向$y_j$連線一條容量為$1$的有向邊(題$j\in$類別$i$),
從$y_i$向$t$連線一條容量為$1$的有向邊,
求最大流.
如果最大流$=m$,則存在解,否則無解。
從集合$x$流向集合$y$的所有滿流邊為當前方案.
#include#include#include
#include
#include
#include
#include
#include
#include
#include
#define m 25
#define n 1005
using
namespace
std;
struct
graphe[m*n<<1
];int a[m],g[n+m],dep[n+m],n,m,s,t,sum,cnt=1
;queue
q;inline
void addedge(int x,int y,int
f)inline
void adde(int x,int y,int
f)inline
bool bfs(int
u) }
return
dep[t];
}inline
int dfs(int u,int
f)
return
ret;
}inline
intdinic()
}inline
void
aireen()
for(int i=1,j,k;i<=n;++i)
adde(i+m,t,1
); }
if(dinic()!=sum) puts("
no solution!");
else
}}int
main()
網路流24題 試題庫問題
網路流24題大多需要spj,所以需要乙個有spj的oj,本系列 均在www.oj.swust.edu.cn測試通過 這道題的模型很顯然,源點向每個試卷連線一條容量為1的邊,每個試卷向對應的型別連線一條容量為一的邊,每個型別向匯點連線一條容量為需要數量的邊,跑一邊最大流即可。include inclu...
網路流24題 試題庫問題
傳送門 這個題好像比較水。每個種類向匯點連容量為所需求的數量的邊 然後每個試題向可以選的種類連容量為1的邊 再從源點向每個試題連容量為1的邊,然後dinic 過程中記錄一下轉移的目標節點,然後輸出路徑就好了 判無解不用我說了吧。include include include include incl...
網路流24題 試題庫問題
有 k k 種型別和 n role presentation n n個題目,每個題目會適應部分型別,一種型別可能需要多種題,一道題可能多種型別都需要,但一道題只能滿足一種型別,現要求出滿足出完所有型別的題目的方案 網路流擅長於解決各種有要求的匹配,顯然這道題是有條件的匹配,可以用最大流來解決。首先建...