题目大意:切割图形,给你一个非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的更多相关文章

  1. Dividing a Chocolate(zoj 2705)

    Dividing a Chocolate zoj 2705 递推,找规律的题目: 具体思路见:http://blog.csdn.net/u010770930/article/details/97693 ...

  2. 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. ...

  3. AtCoder - 2565 枚举+贪心

    There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing thi ...

  4. Chocolate Bar(暴力)

    Chocolate Bar Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement There is ...

  5. POJ 1014 Dividing

    Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...

  6. CF 371B Fox Dividing Cheese[数论]

    B. Fox Dividing Cheese time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. AC日记——Dividing poj 1014

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 69575   Accepted: 18138 Descri ...

  8. POJ 1014 Dividing(多重背包)

    Dividing   Description Marsha and Bill own a collection of marbles. They want to split the collectio ...

  9. Big Chocolate

    Big Chocolate 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19127 Big Chocolat ...

随机推荐

  1. 16. nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "auditUnitName"

    org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver:handleHttpMessageNotRead ...

  2. Redis系列(一):小试牛刀

    引言 随着互联网的高速发展,传统的关系数据库(如MySQL.Microsoft SQL Server等)已不能满足日益增长的业务需求,如商品秒杀.抢购等及时性非常强的功能,随着应用高并发的访问,会造成 ...

  3. GANs和低效映射

    生成对抗网络(GANs)被誉为生成艺术领域的下一纪元,这是有充分理由的.新技术一直是艺术的驱动因素,从颜料的发明到照相机再到Photoshop-GAN是自然而然的.例如,考虑下面的图片,由埃尔加马勒发 ...

  4. SpringCloud服务的注册发现--------consul实现服务与发现

    1,consul也可以替代Eureka实现注册和发现的功能,即注册中心. 之前在linux环境通过consul + upsync + nginx 实现nginx 的动态负载均衡 https://www ...

  5. 使用node.js中遇到的一些小bug

    1.BUG Cannot set headers after they are sent to the client 解决:即发出一次请求得到两次或以上的回应时会出现此警告,此时注意查看再在一些条件下 ...

  6. Oracle, Mysql及Sql Server的区别

    从事技术工作以来,算是把关系型数据库SQL Server,Oracle, MySQL均用了一遍,本文参考网友的梳理,做一下知识总结. 源头说起 Oracle:中文译作甲骨文,这是一家传奇的公司,有一个 ...

  7. 一文读懂什么是CA证书

    Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable ...

  8. 面向对象编程基础(java)

    面向对象编程基础 1.1 面向对象概述 在程序开发初期,大家使用的是结构化开发语言,也就是面向过程(opp),但随着市场需求剧增,软件的规模也越来越大,结构化语言的弊端也暴露出来. 开发周期无休止的拖 ...

  9. PHP友盟推送消息踩坑及处理

    公司的客户端的推送选用友盟推送,但是友盟的官方文档描述很少,对新手很不友好,所以特写此采坑纪录,废话不多说上代码. 公司业务只涉及单播和广播.所以只提供了单播和广播,业务拓展的话会补充其余部分. 消息 ...

  10. LinuxNFS网络文件系统

    LinuxNFS网络文件系统 首先需要准备四台机器,分别为以下服务器 NAS-Server-0 IP:192.168.254.10 Web-Server-1 IP:192.168.254.11 Web ...