【题目链接】

点击打开链接

【算法】

二分答案,check的时候跑最大流,即可

【代码】

#include<bits/stdc++.h>
using namespace std;
#define MAXN 2000
#define MAXB 1000 int i,j,low,high,mid,st,ed,N,B,tot,ans,tmp;
int h[MAXN+MAXB],U[MAXN*MAXB],V[MAXN*MAXB],
W[MAXN*MAXB],Head[MAXN*MAXB],Next[MAXN*MAXB],
other[MAXN*MAXB],v[MAXB+],a[MAXN+][MAXB+]; template <typename T> void read(T &x) {
int f=; char c = getchar(); x=;
for (; !isdigit(c); c = getchar()) { if (c=='-') f = -f; }
for (; isdigit(c); c = getchar()) x=x*+c-'';
x*=f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x % + '');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline void add(int a,int b,int c) {
++tot;
U[tot] = a; V[tot] = b; W[tot] = c;
Next[tot] = Head[a]; Head[a] = tot;
other[tot] = ++tot;
U[tot] = b; V[tot] = a; W[tot] = ;
Next[tot] = Head[b]; Head[b] = tot;
other[tot] = tot - ;
} inline bool bfs() {
int i,x,y;
queue<int> q;
memset(h,,sizeof(h));
h[st] = ; q.push(st);
while (!q.empty()) {
x = q.front(); q.pop();
for (i = Head[x]; i; i = Next[i]) {
y = V[i];
if ((W[i] > ) && (!h[y])) {
h[y] = h[x] + ;
q.push(y);
}
}
}
if (h[ed]) return true;
else return false;
} inline int maxflow(int x,int f) {
int i,t,y,sum=;
if (x == ed) return f;
for (i = Head[x]; i; i = Next[i]) {
y = V[i];
if ((W[i] > ) && (h[y] == h[x] + ) && (sum < f)) {
sum += (t = maxflow(y,min(W[i],f-sum)));
W[i] -= t; W[other[i]] += t;
}
}
if (!sum) h[x] = ;
return sum;
} inline bool check(int ml) {
int i,j,l,r,sum;
for (l = ; l <= N - ml + ; l++) {
r = l + ml - ;
for (i = ; i <= tot; i++) Head[i] = ;
tot = ;
for (i = ; i <= N; i++) add(st,i,);
for (i = ; i <= B; i++) add(i+N,ed,v[i]);
for (i = ; i <= N; i++) {
for (j = ; j <= B; j++) {
if ((a[i][j] >= l) && (a[i][j] <= r))
add(i,j+N,);
}
}
sum = ;
while (bfs()) {
sum += maxflow(st,N);
}
if (sum == N) return true;
}
return false;
} int main() { read(N); read(B);
st = N + B + ; ed = st + ; for (i = ; i <= N; i++) {
for (j = ; j <= B; j++) {
read(tmp);
a[i][tmp] = j;
}
}
for (i = ; i <= B; i++) read(v[i]); low = ; high = B;
while (low <= high) {
mid = (low + high) / ;
if (check(mid)) {
high = mid - ;
ans = mid;
} else
low = mid + ;
}
writeln(ans); return ; }

最新文章

  1. juery学习总结——例子
  2. Linux 文件与目录管理
  3. git 教程(2)--创建版本库
  4. Delphi面向对象编程
  5. 【iCore3 双核心板_FPGA】Quartus 如何生成jic文件
  6. Blend Tree Type
  7. mismatch位置(MD tag)- sam/bam格式解读进阶
  8. catalan数及笔试面试里那些相关的问题(转)
  9. Linux下C程序的编辑,编译和运行以及调试
  10. PowerShell3.0中,所有的命令
  11. spring securiy使用总结
  12. Word常用实用知识2
  13. Hibernate由model类自动同步数据库表结构
  14. 数据库表反向生成(二) Django ORM inspectdb
  15. java网络编程基本知识
  16. 【json】与【枚举】的序列化和反序列化
  17. 20164319 刘蕴哲 Exp4:恶意代码分析
  18. base64图片
  19. 基于神经网络的颜色恒常性—Fully Convolutional Color Constancy with Confidence-weighted Pooling
  20. Spring配置表友好性优化思路

热门文章

  1. CentOS 7.5 初始网络配置
  2. git(一):了解、学习、安装git
  3. B站papi酱、陈一发、李云龙
  4. 王立平--Gallery:实现图片的左右滑动
  5. [转]java中的字符串相关知识整理
  6. 最近遇到的C++数字和字符串的转换问题
  7. UVa567_Risk(最短路)(小白书图论专题)
  8. 【转载】lvs为何不能完全替代DNS轮询
  9. [LeedCode OJ]#28 Implement strStr()
  10. 基于SpringMVC框架使用ECharts3.0实现折线图,柱状图,饼状图,的绘制(上篇)