BNU 33693——Problemsetting——————【枚举+最大流】
Problemsetting
64-bit integer IO format: %lld Java class name: Main
None
Graph Theory
2-SAT
Articulation/Bridge/Biconnected Component
Cycles/Topological Sorting/Strongly Connected Component
Shortest Path
Bellman Ford
Dijkstra/Floyd Warshall
Euler Trail/Circuit
Heavy-Light Decomposition
Minimum Spanning Tree
Stable Marriage Problem
Trees
Directed Minimum Spanning Tree
Flow/Matching
Graph Matching
Bipartite Matching
Hopcroft–Karp Bipartite Matching
Weighted Bipartite Matching/Hungarian Algorithm
Flow
Max Flow/Min Cut
Min Cost Max Flow
DFS-like
Backtracking with Pruning/Branch and Bound
Basic Recursion
IDA* Search
Parsing/Grammar
Breadth First Search/Depth First Search
Advanced Search Techniques
Binary Search/Bisection
Ternary Search
Geometry
Basic Geometry
Computational Geometry
Convex Hull
Pick's Theorem
Game Theory
Green Hackenbush/Colon Principle/Fusion Principle
Nim
Sprague-Grundy Number
Matrix
Gaussian Elimination
Matrix Exponentiation
Data Structures
Basic Data Structures
Binary Indexed Tree
Binary Search Tree
Hashing
Orthogonal Range Search
Range Minimum Query/Lowest Common Ancestor
Segment Tree/Interval Tree
Trie Tree
Sorting
Disjoint Set
String
Aho Corasick
Knuth-Morris-Pratt
Suffix Array/Suffix Tree
Math
Basic Math
Big Integer Arithmetic
Number Theory
Chinese Remainder Theorem
Extended Euclid
Inclusion/Exclusion
Modular Arithmetic
Combinatorics
Group Theory/Burnside's lemma
Counting
Probability/Expected Value
Others
Tricky
Hardest
Unusual
Brute Force
Implementation
Constructive Algorithms
Two Pointer
Bitmask
Beginner
Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
Greedy
Divide and Conquer
Dynamic Programming
Tag it!
It's well-known that different programming contests require different kind of problems. For example, maximal array size for TopCoder problem is only 50, and you definitely can not give a Suffix Tree problem to IOI because children will not have a chance to solve it (except of some touristic-inclined ones). Thus not every problem is acceptable for every contest.
You are preparing problemsets for N different contests. These contests require different number of problems, depending of type. For example, ACM ICPC style problemset usually has 10 problems, TopCoder SRM - 5 and so on.
Luckily you have already prepared M different problems. For each problem you have determined a set of contests you can give that problem to. Also you know the required number of problems for each contest.
Find out the maximal number of different contests for which you can simultaneously compose complete problemsets from the given set of problems. All problems in the problemsets must be unique, i.e. no problem can be used twice in different problemsets.
Input
The input file contains several test cases.
The first line of each test case contains 2 integers N and M (1 < N < 15, 0 < M < 50) - the number of different contests and the number of prepared problems. Each of the followingN lines contains the name of contest, followed by the required number of problems for that contest. The name of a contest consists of lower - and uppercase Latin letters and/or digits, is not empty and does not exceed 100 characters. Contest names are case-sensitive. It's guaranteed that all contest names will be pairwise different. The required number of problems does not exceed 100.
Each of the following M lines contains a (possibly empty) list of acceptable contest names for each problem, separated by a single space. It's guaranteed that all contest names will be correct (i.e., noted in the previous section of the current test case) and unique.
The line containing two zeroes indicates the end of the input file.
For each test case print an answer for that case on a new line, as shown in the sample output.
Sample Input
4 5
IOI 3
IPSC 2
TopCoder 2
SEERC 10
IOI
IPSC TopCoder
IOI IPSC
IOI IPSC
TopCoder SEERC
1 1
SampleContest 1
SampleContest
0 0
Sample Output
Case #1: 2
Case #2: 1
Source
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int mod = 1e9+7;
const int maxn = 100;
const int INF = 0x3f3f3f3f; int Map[55][55];
int need[55];
struct Edge{
int from, to, next, cap, flow;
Edge(){}
Edge(int _from, int _to, int _cap, int _flow):from(_from), to(_to), cap(_cap),flow(_flow){}
};
int contest_table[20];
vector<Edge>edges;
vector<int>G[maxn];
void AddEdge(int from, int to, int cap){
edges.push_back(Edge(from, to, cap, 0));
edges.push_back(Edge(to, from, 0, 0));
int m = edges.size();
G[from].push_back(m - 2);
G[to].push_back(m - 1);
}
int capacity[maxn];
struct Dinic{
int s, t; // bool vis[maxn];
int d[maxn];
int cur[maxn];
bool BFS(){
memset(vis,0,sizeof(vis));
queue<int>Q;
Q.push(s);
d[s] = 0;
vis[s] = 1;
while(!Q.empty()){
int x = Q.front(); Q.pop();
for(int i = 0; i < G[x].size(); ++i){
Edge &e = edges[G[x][i]];
if(!vis[e.to] && e.cap > e.flow){
vis[e.to] = 1;
d[e.to] = d[x] + 1;
Q.push(e.to);
}
}
}
return vis[t];
}
int DFS(int x,int a){
if(x == t || a == 0) return a;
int flow = 0, f;
for(int &i = cur[x]; i < G[x].size(); i++){
Edge &e = edges[G[x][i]];
if(d[x] + 1 == d[e.to]&&(f = DFS(e.to, min(a,e.cap - e.flow))) > 0){
e.flow += f;
edges[G[x][i]^1].flow -= f;
flow += f;
a -= f;
if(a == 0) break;
}
}
return flow;
}
int Maxflow(int s,int t){
this->s = s; this->t = t;
int flow = 0;
while(BFS()){
memset(cur,0,sizeof(cur));
flow += DFS(s, INF);
}
return flow;
}
}; int n, m;
int constructG(int enumc){
for(int i = 0; i <= n+m+10; i++){
G[i].clear();
}
edges.clear();
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(Map[i][j]){
AddEdge(i, n+j, 1);
}
}
}
for(int i = 1; i <= m; i++){
AddEdge(n+i,n+m+1,1);
}
int ret = 0;
for(int i = 1; i <= n; i++){
if(enumc&1){
AddEdge(0, i, capacity[i]);
ret += need[i];
}
enumc /= 2;
}
return ret;
}
int main(){
string str;
int cas = 0;
char s[100000];
while(scanf("%d%d",&n,&m)!=EOF&&(n+m) != 0){
map<string,int>mp;
int c;
for(int i = 1; i <= n; i++){
scanf("%s",s);
str = s;
mp[str] = i;
scanf("%d",&need[i]);
}
memset(Map,0,sizeof(Map));
memset(capacity,0,sizeof(capacity));
getchar(); getchar();
for(int i = 1; i <= m; i++){
str = "";
gets(s);
int len = strlen(s);
for(int j = 0; j < len-1; j++) {
if(s[j]==' '&&j!=0){
if(s[j-1]!=' '){
Map[mp[str]][i]=1;
capacity[mp[str]]++;
}
str="";
}else if(s[j]!=' ') str+=s[j];
}
if(str!="") {
Map[mp[str]][i]=1;
capacity[mp[str]]++;
}
}
int enumc = (int)pow((double)2,(double)n);
int ans = 0;
Dinic ansf;
for(int i = 0; i < enumc; i++){
int j = i, cnum = 0, c = 0;
while(j){
if(j&1)
cnum++;
j = j >> 1;
}
if(ans >= cnum) continue;
int needMaxf = constructG(i);
int Maxf = ansf.Maxflow(0,n+m+1);
if(Maxf >= needMaxf){
ans = cnum;
}
}
printf("Case #%d: ",++cas);
printf("%d\n",ans);
}
return 0;
}
BNU 33693——Problemsetting——————【枚举+最大流】的更多相关文章
- hust-1024-dance party(最大流--枚举,可行流判断)
题意: 舞会上,男孩和女孩配对,求最大完全匹配个数,要求每个人最多与k个不喜欢的人配对,且每次都和不同的人配对. 分析: 将一个点拆成3个点. b, b1, b2. 从1到n枚举ans, 判可 ...
- poj 2699 The Maximum Number of Strong Kings 枚举 最大流
题目链接 题意 对于一个竞赛图(有向完全图),其顶点是选手,边是比赛,边\(e=(u,v)\)代表该场比赛中\(u\)战胜\(v\). 现定义选手的分数为其战胜的人的个数(即竞赛图中点的出度).并且定 ...
- hdu4807枚举费用流
题意: 给你一个有向图,每条边上都有每一时刻的最大流量,有k个人在点0,他们要去点n-1,问你最晚到达的那个人最快要多久. 思路: 这个题目做了很多次,用过费用流,也用过最大流,结 ...
- poj2699 转化为可行性判定问题+二分枚举+最大流
The Maximum Number of Strong Kings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2302 ...
- USACO 5.4 Telecowmunication(最大流+枚举)
面对最小割之类的题目,完全木想法... 枚举+最大流..复杂度很大了...居然很快的就过了.. /* ID: cuizhe LANG: C++ TASK: telecow */ #include &l ...
- POJ3228 并查集或二分最大流枚举答案
忘记写题意了.这题题意:给出每个地点的金矿与金库的数量,再给出边的长度.求取最大可通过边长的最小权值使每个金矿都能运输到金库里. 这题和之前做的两道二分枚举最大流答案的问法很相识,但是这里用最大流速度 ...
- Intel RealSense SDK 简翻
:first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0,.1);border-radius:3px ...
- ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)
[题意]给出一个带权无向图,求割集,且割集的平均边权最小. [分析] 先尝试着用更一般的形式重新叙述本问题.设向量w表示边的权值,令向量c=(1, 1, 1, --, 1)表示选边的代价,于是原问题等 ...
- 最小截断[AHOI2009]
[题目描述] 宇宙旅行总是出现一些意想不到的问题,这次小可可所驾驶的宇宙飞船所停的空间站发生了故障,这个宇宙空间站非常大,它由N个子站组成,子站之间有M条单向通道,假设其中第i(1<=i< ...
随机推荐
- android的样式(style)与主题(theme)
Android上的Style分为了两个方面: 1,Theme是针对窗体级别的,改变窗体样式: 2,Style是针对窗体元素级别的,改变指定控件或者Layout的样式. Android系统的themes ...
- Linux Centos下SQL Server 2017安装和配置
说到SQL Server服务,我们大家都知道是Microsoft公司的数据库服务,当然说到数据库,现在主要分为三大商:1:Oracle.2:Msql Server.3:Mysql:三种数据库在当下环境 ...
- 一键生成ssl自签名证书脚本
#!/bin/bash -e # * 为必改项 # * 更换为你自己的域名 CN='' # 例如: demo.rancher.com # 扩展信任IP或域名 ## 一般ssl证书只信任域名的访问请求, ...
- [bzoj2816][ZJOI2012]网络(LCT,splay)
传送门 题解 话说以前还真没见过用LCT只维护一条链的……好像除了树点涂色那题…… 先看一下题目规定的两个性质 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环,同色的环指相同颜 ...
- springboot 搭建 简单 web项目 【springboot + freemark模板 + yml 配置文件 + 热修复 + 测试用例】附源码
项目 地址: https://gitee.com/sanmubird/springboot-simpleweb.git 项目介绍: 本项目主要有一下内容: 1: springboot yml 配置 ...
- HTML-文本域属性设置
1.设置文本域的字体 <TEXTAREA STYLE="font-size:9pt;font-family:verdana;color:#333333">输入内容< ...
- 51 Nod 1024 Set
1024 矩阵中不重复的元素 1 秒 131,072 KB 10 分 2 级题 一个m*n的矩阵. 该矩阵的第一列是a^b,(a+1)^b,.....(a + n - 1)^b 第二列是a^( ...
- NVIDIA TX1/TX2 对比
处理器方面,TX2由TX1的Tegra X1升至Tegra Parker处理器,该处理器由16nm工艺制造,6核心设计,CPU部分由2个丹佛+4个A57核心共同组成. GPU则采用Pascal架构,拥 ...
- bzoj 4032(A的一个最短的子串,它不是B的子串 || A的一个最短的子串,它不是B的子序列 || A的一个最短的子序列,它不是B的子串||A的一个最短的子序列,它不是B的子序列)
在虐各种最长公共子串.子序列的题虐的不耐烦了之后,你决定反其道而行之. 一个串的“子串”指的是它的连续的一段,例如bcd是abcdef的子串,但bde不是. 一个串的“子序列”指的是它的可以不连续的一 ...
- Linux下安装渗透测试框架Metasploit
我们先来说一种方法,直接从github来下载: git clone --depth=1 git://github.com/rapid7/metasploit-framework metasploit ...