5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

Time Limits: 1000 ms Memory Limits: 262144 KB

Description

Input

Output

Sample Input

5 5

1 4 0 5 2

2 1 2 0 1

0 2 3 4 4

0 3 0 3 1

1 2 2 1 1

Sample Output

9

Data Constraint

Hint

题解

乍一看以为是贪心,贪心保留最大的

后来,发现有个诡异的地方

这是一个会搬砖的小偷

于是,只能用二分图了

如果第i行和第j列最大值相等且可以放,就连一条边

跑一遍匹配匹配到的边就只算一次,代表只放一个就能满足一行和一列

匹配不到的行和列,就分别算一次

代码

#include<cstdio>
#include<cstring>
#include<vector>
#define N 101
using namespace std; vector<long>map[N];
long a[N][N],link[N],hang[N],lie[N];
bool cover[N]; bool find(long now)
{ long i,to;
for(i=0;i<map[now].size();i++){
to=map[now][i];
if(!cover[to]){
cover[to]=true;
if(!link[to]||find(link[to])){
link[to]=now;
return true;
}
}
}
return false;
} int main()
{ long n,m,i,j,ans=0,sum=0;
scanf("%ld%ld",&n,&m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++){
scanf("%ld",&a[i][j]);
hang[i]=max(hang[i],a[i][j]);
lie[j]=max(lie[j],a[i][j]);
if(a[i][j])
sum+=a[i][j]-1;
}
for(i=1;i<=n;i++)
if(hang[i])ans+=hang[i]-1;
for(j=1;j<=m;j++)
if(lie[j])ans+=lie[j]-1;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++){
if(hang[i]==lie[j]&&a[i][j])
map[i].push_back(j);
}
for(i=1;i<=n;i++){
memset(cover,false,sizeof(cover));
if(find(i))
ans-=hang[i]-1;
}
printf("%ld\n",sum-ans);
return 0;
}

JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)的更多相关文章

  1. JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠

    JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...

  2. JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)

    5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...

  3. [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)

    题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...

  4. 【NOIP2017提高A组模拟9.7】JZOJ 计数题

    [NOIP2017提高A组模拟9.7]JZOJ 计数题 题目 Description Input Output Sample Input 5 2 2 3 4 5 Sample Output 8 6 D ...

  5. JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团

    100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits   Got ...

  6. JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线

    5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...

  7. JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器

    5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...

  8. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  9. 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人

    [NOIP2017提高A组模拟9.17]信仰是为了虚无之人 Description Input Output Sample Input 3 3 0 1 1 7 1 1 6 1 3 2 Sample O ...

随机推荐

  1. Spring Boot中@Async的作用

    在Spring中,@Async这个注解用于标记的异步的方法.方法上一旦标记了这个方法,当其它线程调用这个方法时,就会开启一个新的线程去异步处理业务逻辑. 此注解的使用说明: 1.此注解可以用在方法上, ...

  2. crm项目-业务实现

    ###############  crm业务    ############### """ 校区管理,部门管理,课程管理, 这三个都比较简单 1,只需要展示校区名称,这是 ...

  3. Office 365管理员设置

    一.注册 1.输入网站 http://www.21vbluecloud.com/  ,进入世纪互联蓝云官方网站 2.选择 运营的产品->Office 365 3.选择了解更多 4.浏览根据不同的 ...

  4. ValidationUtil

    package me.zhengjie.common.utils; import me.zhengjie.common.exception.BadRequestException; import ja ...

  5. http接口与webservice接口的区别

    常见的API接口有两类:http接口和webservice接口. http接口走http协议,通过路径来区分调用方法,请求报文一般是key-value形式的,返回报文一般是json串,常用的是get和 ...

  6. 吴裕雄--天生自然 python开发学习:在Cenos 7 系统上安装配置python3.6.5

    安装相关依赖包. 在终端下输入命令:sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-deve ...

  7. SQL语言:DDL,DML,DCL,DQL,TCL

    DDL(Data Definition Language)数据库定义语言 statements are used to define the database structure or schema. ...

  8. HDU-1403-Longest Common Substring(后缀数组的高度数组运用)

    这题要求两个串中的最长相同子串的长度.高度数组可以求一个串中的最长相同子串的长度.所以想到把两个串连起来,但是这样又会产生一些新的串(第一个串的结尾和第二个串的开头组成的)于是在两个串中间放一个'\0 ...

  9. 微信小游戏广告位iphonex底部适配问题

    最近在公司开发游戏,使用cocos creator做微信小游戏,遇到一个很恶心的问题,如图: 如图所示,微信的广告位被iphonex的底部bar给弹出了一点位置,没有靠在底部. 在这里不得不吐槽一下微 ...

  10. Nginx笔记总结十四: nginx反向代理,用内网域名转发

    user www www; worker_processes ; error_log logs/error.log; pid logs/nginx.pid; worker_rlimit_nofile ...