E - Dividing Chocolate ATcoder
题目大意:切割图形,给你一个非0即1的矩阵,将它切割成多个长方形,使每个小长方形中1的个数不得多于k个,切割的规则,要么切一整行,要么是一整列、

题解: 二进制枚举。
注意行数最大才是10。用二进制枚举切割某一行,然后在枚举每一列是否需要切割。时间复杂度O(2^h*m)
code:
#include<bits/stdc++.h>
using namespace std;
const int N=1E3+;
const int INF=1e9+;
int mp[N][N];
int arr[N];
int n,m,k;
vector<int>ve;
int cal(int x,int y,int j){//用来计算第从x到y行第j列的值。
int sum=;
for(int i=x;i<=y;i++)
sum+=mp[i][j];
return sum;
}
int check(){
int c=ve.size(),sum=;
for(int k1=;k1<c;k1++) arr[k1]=;
bool flag=;
for(int j=;j<=m;j++){
for(int k1=;k1<c;k1++){
arr[k1]+=cal(ve[k1-]+,ve[k1],j);
if(arr[k1]>k){
sum++;
flag=;
break;
}
}
if(!flag) continue ;
flag=;
for(int k1=;k1<c;k1++){
arr[k1]=cal(ve[k1-]+,ve[k1],j);
if(arr[k1]>k) return INF;
}
}
return sum;
}
int main(){
cin>>n>>m>>k;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
char x;
cin>>x;
if(x=='') mp[i][j]=;
else mp[i][j]=;
}
}
int c=(<<(n-))-;
int ans=INF;
for(int i=;i<=c;i++){
ve.push_back();
for(int j=;j<n-;j++)
if((<<j)&i) ve.push_back(j+);
ve.push_back(n);
int x=ve.size();
ans=min(ans,x-+check());
ve.clear();
}
cout<<ans<<endl;
return ;
}
E - Dividing Chocolate ATcoder的更多相关文章
- Dividing a Chocolate(zoj 2705)
Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...
- Atcoder Regular-074 Writeup
C - Chocolate Bar 题面 There is a bar of chocolate with a height of H blocks and a width of W blocks. ...
- AtCoder - 2565 枚举+贪心
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing thi ...
- Chocolate Bar(暴力)
Chocolate Bar Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement There is ...
- POJ 1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...
- CF 371B Fox Dividing Cheese[数论]
B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...
- AC日记——Dividing poj 1014
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 69575 Accepted: 18138 Descri ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- Big Chocolate
Big Chocolate 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19127 Big Chocolat ...
随机推荐
- django之 F与Q查询
F与Q查询 F查询 why?
- 凸包问题 Graham Scan
2020-01-09 15:14:21 凸包问题是计算几何的核心问题,并且凸包问题的研究已经持续了好多年,这中间涌现出了一大批优秀的算法. 凸包问题的最优解法是Graham Scan算法,该算法可以保 ...
- 一夜搞懂 | JVM GC&内存分配
前言 本文已经收录到我的Github个人博客,欢迎大佬们光临寒舍: 我的GIthub博客 学习导图 一.为什么要学习GC&内存分配? 时代发展到现在,如今的内存动态分配与内存回收技术已经相当成 ...
- CompletableFuture异步编排
什么是CompletableFuture CompletableFuture是JDK8提供的Future增强类.CompletableFuture异步任务执行线程池,默认是把异步任务都放在ForkJo ...
- FtpServer穿透内网访问配置踩笔记
FtpServer穿透内网访问配置踩笔记 引言 FtpServer是服务器文件远程管理常用方式. 以前在局域网配置Ftp服务器以及使用公网上的Ftp服务均未碰到问题,固未对Ftp传输进行深入了解. 然 ...
- CSS三角形/气泡的实现原理及应用
记得第一次面试,面试官问如何用css实现一个不规则三角形?好叭 ·-·,触及到知识盲区了,手动叹气(╥﹏╥),好在别的回答的还好,没挂
- Jmeter接口测试实战之HTTP Cookie管理器(十二 )
在使用测试工具Jmeter做接口测试中,怎么记录下它登录成功后的信息,在接口测试的应用场景中,一般对业务的操作都是基于用户登录情况下的操作.它的测试步骤相对来说很简单的,其实在Jmeter的测试工具中 ...
- linux-aapt文件调用问题
使用管理后台上传移动app安装包到服务器,出现异常问题,解决方案如下: 本地环境说明: 系统:linux(centos 64位) 远程工具:xshell 数据库:oracle 中间件:weblogic ...
- 如何搭建本地web服务
IIS服务是windows自带的web服务,我们可以用来搭建本地网站,供局域网内的用户之前访问,比如办公室的同事之间,一个教室里的同学们. 先说明这是Windows10 x64位 家庭普通版的系统. ...
- TensorFlow报错module 'tensorflow' has no attribute 'xxx'解决办法
原因:TensorFlow2.0版本修改了许多函数名字 tf.sub()更改为tf.subtract() tf.mul()更改为tf.multiply() tf.types.float32更改为tf. ...