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 ...
随机推荐
- Python 趣题
如何优雅判断list为空 list_temp = [] if list_temp: # 存在值即为真 else: # list_temp是空的 在Python中,False,0,'',[],{},() ...
- 收藏 | 15 个你非了解不可的 Linux 特殊字符,妈妈再也不用担心我看不懂这些符号了!
不知道大家接触 Linux 系统有多久了,可曾了解过 Linux 中有哪些特殊的字符呢?其实啊,那些特殊字符都大有用处呢,今天的文章就给大家简单地科普一下 Linux 中你需要了解的 15 个特殊字符 ...
- Visdom 介绍 | 二
用于创建,组织和共享实时丰富数据可视化的灵活工具.支持Python. 概述 概念 设置 用法 API 注意事项 贡献 API 要快速了解visdom的功能,请查看example目录,或阅读以下详细信息 ...
- 字典树模板 HDU - 1251
题意: 给一些单词,换行键后,查找以后输入的单词作为前缀的话们在之前出现过几次. 思路: 字典树模板----像查字典的顺序一样 #include<string> #include<s ...
- PIGS POJ - 1149网络流(最短增广路---广搜) + 建图
题意: 第一行输入m和n,m是猪圈的数量,n是顾客的数量,下面n行 第 i+1行表示第i个顾客 , 输入第一个数字表示有几把猪圈的钥匙,后面输入对应的猪圈,最后一个数字输入顾客想买几头猪. 建图: 设 ...
- MFC之登录框的问题处理
1.在做登录框的时候,把登录框做成模态对话框,并且放在 主界面程序所在窗口打开之前.也就是放在主界面类的InitInstance()里.这样做就会在弹出主界面之前被登录框弹出模态框出来阻塞住. 1.但 ...
- JVM tomcat 性能调优
1,新建web 测试项目并且发布到Tomcat,访问路径:http://127.0.0.1:8080/JvmWeb/index @WebServlet("/index") publ ...
- Java 获取 IP
/** * 获取访问者IP. * 在一般情况下使用 Request.getRemoteAddr() 即可,但是经过 nginx 等反向代理软件后,这个方法会失效. */ private String ...
- php连接数据库,php连接mysql并查询的几种方式,PHP PDO连接以及预处理
PHP连接数据库 面向过程 $config = [ 'host'=>'127.0.0.1', //数据库地址 'name'=>'test', //库名 'user'=>'root', ...
- php--MongoDB的使用
添加 $collection = (new MongoDB\Client)->test->users; // 增加一条 $insertOneResult = $collection-> ...