题目大意:切割图形,给你一个非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. rest_framework之认证与权限 token不存数据库认证

    1. 认证 : 介绍: UserInfo表包含name , pwd , user_type三个字段 UserToken表包含token与user(关联UserInfo表) 当用户登录成功将随机字符串写 ...

  2. priority_queue 中存放pair时,自定义排序的写法

    struct cmp {template <typename T, typename U> bool operator()(T const &left, U const & ...

  3. Trie树-0/1字典树-DFS-1624. 最大距离

    2020-03-18 20:45:47 问题描述: 两个二进制串的距离是去掉最长公共前缀的长度之和.比如: 1011000和1011110的最长公共前缀是1011, 距离就是 len("00 ...

  4. Node/Python 工具搭建cmder和nrm

    一.安装cmder cmder是windows下的一款终端工具,支持很多linux命令,用起来还是很爽的. 1.安装 http://cmder.net/ 直接在官网下载,解压即可. 2.cmder配置 ...

  5. 【深度学习】perceptron(感知机)

    目录 1.感知机的描述 2.感知机解决简单逻辑电路,与门的问题. 2.多层感应机,解决异或门 个人学习笔记,有兴趣的朋友可参考. 1.感知机的描述 感知机(perceptron)由美国学者Frank ...

  6. 大规模机器学习(Large Scale Machine Learning)

    本博客是针对Andrew Ng在Coursera上的machine learning课程的学习笔记. 目录 在大数据集上进行学习(Learning with Large Data Sets) 随机梯度 ...

  7. 最简单的 TensorFlow 代码,TensorFlow Hello World 。

    # -*- coding:utf-8 -*- from __future__ import print_function ''' HelloWorld example using TensorFlow ...

  8. iOS nil,Nil,NULL,NSNULL的区别

    nil (id)0 是OC对象的空指针,可正常调用方法(返回空值,false,零值等) Nil  (Class)0 是OC类的空指针,主要运用于runtime中,Class c = Nil; 其他特性 ...

  9. B - Charlie's Change

    Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he often buys coffe ...

  10. c期末笔记(1)

    运算符 1.i++与++i的细微区别 i++与++i 和i++放在一个语句中,则i原本的值先被利用.语句结束后,i的值加一. i的原始值失效,直接加一. 2.int加法 整形数据(int)加上任何类型 ...