[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=1169

[算法]

首先DFS枚举出横着切的

然后二分 + 贪心即可

时间复杂度 : O(2 ^ N * N ^ 2logN)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define N 20
const int inf = 2e9; int n , m , r , s , cnt;
ll ans;
ll a[N][N] , sum[N][N] , dp[N][N] , b[N]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline int calc(int x)
{
int ret = ;
for (int i = x; i; i -= i & (-i))
++ret;
return ret;
}
inline ll calc_sum(int X1 , int Y1 , int X2 , int Y2) {
return sum[X2][Y2] - sum[X1 - ][Y2] - sum[X2][Y1 - ] + sum[X1 - ][Y1 - ];
}
inline bool check(ll limit) {
int pre = , cut = ;
for (int i = ; i <= m; ++i) {
for (int j = ; j <= cnt; ++j) {
if (calc_sum(b[j - ] + , i , b[j] , i) > limit)
return false;
}
}
for (int i = ; i <= m; ++i) {
ll value = ;
for (int j = ; j <= cnt; ++j) {
if (calc_sum(b[j - ] + , pre , b[j] , i) <= limit)
continue;
else {
pre = i;
++cut;
}
}
}
return cut <= s;
}
inline ll getans(ll S) {
cnt = ;
for (int i = ; i < n; ++i)
if (S & ( << i)) b[++cnt] = i + ;
b[++cnt] = n;
ll l = , r = ans , ret = inf;
while (l <= r) {
int mid = (l + r) >> ;
if (check(mid))
{
ret = mid;
r = mid - ;
} else l = mid + ;
}
return ret;
} int main() { read(n); read(m); read(r); read(s);
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
read(a[i][j]);
sum[i][j] = sum[i - ][j] + sum[i][j - ] - sum[i - ][j - ] + a[i][j];
}
}
ans = sum[n][m];
for (int i = ; i < ( << n); ++i)
{
if (calc(i) == r)
chkmin(ans , getans(i));
}
printf("%lld\n" , ans); return ; }

[BALTIC 2008] Grid的更多相关文章

  1. 洛谷 P4660 & bzoj 1168 [ Baltic OI 2008 ] 手套 —— 分析+单调栈

    题目:https://www.luogu.org/record/show?rid=12702916 https://www.lydsy.com/JudgeOnline/problem.php?id=1 ...

  2. 为WPF和Silverlight的Grid添加边框线(zz)

      Grid是WPF和Silverlight中的一个重要的布局元素,其他的布局元素还有StackPanel, Canvas, Border等等.从字面上说,Grid是一个表格的意思,它的使用也确实很方 ...

  3. Repeat Header / Keep Header Visible in Tables in RS 2008

    You selected "Repeat header rows on each page" or "Keep header rows visible while scr ...

  4. Oracle RAC集群安装之:Grid软件安装过程蓝屏

    前几天在安装一套RAC服务器的过程中,遇到了蓝屏事件,折腾了蛮久(在排查是否存在硬件问题上花费了相当多一部分时间),整个过程大概说明如下: 1.两台华为的PC SERVER,操作系统为WIN SERV ...

  5. jQuery的几个Grid插件简单比较

    目标:实现一个类似于Excel功能的Grid数据维护功能,并且就地编辑在乎的是Cell编辑而不是行编辑 候选者:easy-ui之datagrid, jqgrid, flexigrid 使用环境:jqu ...

  6. SQL Server 2008空间数据应用系列十二:Bing Maps中呈现GeoRSS订阅的空间数据

    原文:SQL Server 2008空间数据应用系列十二:Bing Maps中呈现GeoRSS订阅的空间数据 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Se ...

  7. Deploy 11.2.0.3 RAC+DG on Windows 2008 R2 Step by Step

    环境规划: 节点1: tc1 192.168.56.101 内存:2G 节点2: tc2 192.168.56.102 内存:2G 物理备库:tcdg192.168.56.108内存:1.5G 操作系 ...

  8. 重新想象 Windows 8 Store Apps (7) - 控件之布局控件: Canvas, Grid, StackPanel, VirtualizingStackPanel, WrapGrid, VariableSizedWrapGrid

    原文:重新想象 Windows 8 Store Apps (7) - 控件之布局控件: Canvas, Grid, StackPanel, VirtualizingStackPanel, WrapGr ...

  9. 背水一战 Windows 10 (38) - 控件(布局类): Panel, Canvas, RelativePanel, StackPanel, Grid

    [源码下载] 背水一战 Windows 10 (38) - 控件(布局类): Panel, Canvas, RelativePanel, StackPanel, Grid 作者:webabcd 介绍背 ...

随机推荐

  1. Kafka具体解释二、怎样配置Kafka集群

    Kafka集群配置比較简单,为了更好的让大家理解.在这里要分别介绍以下三种配置 单节点:一个broker的集群 单节点:多个broker的集群 多节点:多broker集群 一.单节点单broker实例 ...

  2. Js拼接html并给onclick传多个参数

    return '<a id="" class="ace_button" href="#" onclick="showItem ...

  3. Office 2013“永久激活信息”备份

    Office 2013“永久激活信息”备份还原简明教程及成功恢复的注意事项Office 2013永久激活后及时备份激活信息可以保证重装后快速激活.网上也有流行的各种备份工具,虽然操作简单,但是如果不理 ...

  4. JVM 性能优化, Part 4: C4 垃圾回收

    ImportNew注:本文是JVM性能优化 系列-第4篇.前3篇文章请参考文章结尾处的JVM优化系列文章.作为Eva Andreasson的JVM性能优化系列的第4篇,本文将对C4垃圾回收器进行介绍. ...

  5. Django——自定义分页(可调用)

    1.view from django.shortcuts import render,HttpResponse # Create your views here. from app01.models ...

  6. 找到最大或最小的N个值

    对于python原生的数据类型来说,并不存在直接的方法可以找到最大或最小的N个值, 传统的方法必须先排序,然后再截取相应的值,而且对于集合这类数据类型来说还不能直接排序, 需要先转化为列表才行,有的时 ...

  7. window.location.assign和window.location.href区别

    window.location.assign和window.location.href区别 window.location.assign(url)和window.location.href=url实现 ...

  8. 《程序员代码面试指南》第一章 栈和队列 最大值减去最小值小于或等于num的数量

    题目 给定整数数组arr和整数num,共返回多少的数组满足如下情况 max(arr[i...j]) - min(arr[i...j]) <= num max(arr[i...j])表示数组arr ...

  9. 【三】MongoDB文档的CURD操作

    一.插入文档 使用insert方法插入文档到一个集合中,如果集合不存在创建集合,有以下几种方法: db.collection.insertOne({}):(v3.2 new)  #插入一个文档到集合中 ...

  10. day6 装饰器总结

    装饰器:开放封闭原则,为一个函数加上新的功能,不改变原函数,不改变调用方式 def fun2(wtf): def fun3(): print('i am pythoner!!! ') wtf() re ...