[题目链接]

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. springMVC的注释集合

    SpringMVC的工作原理 主要核心实现是DispatcherServlet. 一般来讲客户端对服务器发送请求,是由DispatcherServlet控制的,DispatcherServlet接受到 ...

  2. poj1845(二分快速求等比数列模M和)

    Sumdiv Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17039   Accepted: 4280 Descripti ...

  3. ABAP制作密码输入框

    [转自 http://blog.csdn.net/saphome/article/details/6956911] 这几天做一个系统维护的程序,需要用户输入用户名和密码登录.可怎样实现输入密码显示星号 ...

  4. 网络的分层协议总结(转发:https://www.cnblogs.com/Zhang-wj/p/5907534.html)

    网络的分层协议总结 OSI七层模型OSI 中的层            功能                                                        TCP/IP ...

  5. cordova屏幕尺寸

    <platform name="android"> <!-- ldpi : 36x36 px mdpi : 48x48 px hdpi : 72x72 px xh ...

  6. css属性background

    一.background-size 1.具体设定的px值,及北背景图片的具体宽高 2.设定的百分比,相对于容器的宽高 3.设定三个铺设类型: (1)cover: 以宽 / 高 为基本,尽可能的去铺满整 ...

  7. 第一天 格式化操作符 条件、for、while、break、continue语句

    python2和3的区别: 2中的print 不必加括号 3中的print变为函数 要加括号   2中的input不能输入字母(输入的字母被认为是变量,而之前又没定义,所以报错),默认只能计算数字,要 ...

  8. min/max优化,count ,group by

    min/max优化 在表中,一般都是经过优化的. 如下地区表 id area pid 1 中国 0 2 北京 1 ... 3115 3113 我们查min(id), id是主键,查Min(id)非常快 ...

  9. LINQ 学习路程 -- 查询操作 Skip SkipWhile Take TakeWhile

    Method Description Skip 跳过序列中指定数量元素,然后返回剩余序列 SkipWhile 只要满足条件,就跳过序列中的元素,然后返回剩余函数 Take 从序列的开头返回指定数量的连 ...

  10. JSP&EL 内置对象

    JSP&EL 内置对象 转载▼   具体的JSP和El中的内置对象见下表,由于我写在了excel中,也不知道怎么把excel发出来,就截了图. 相关问题: Q1: JSP:EL中 pageCo ...