[题目链接]

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. Android 适配(drawable文件夹)图片适配(二)

    参考自(https://blog.csdn.net/myoungmeng/article/details/54090891) Android资源文件存放: android的drawable文件一共可以 ...

  2. 洛谷P1038 神经网络==codevs1088 神经网络

    P1038 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神 ...

  3. Hibernate Criteria 查询使用

    转载 http://blog.csdn.net/woshisap/article/details/6747466 Hibernate 设计了 CriteriaSpecification 作为 Crit ...

  4. 九度OJ 1192:回文字符串 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3807 解决:1778 题目描述: 给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的. 输入: 输入包括一行字符串 ...

  5. 6.2.1-FactoryBeanRegistrySupport(未全)

    FactoryBeanRegistrySupport 的关系图: 添加工厂方式创建类FactoryBean的支持

  6. why factory pattern and when to use factory pattern

    1 factory pattern本质上就是对对象创建进行抽象 抽象的好处是显然的,可以方便用户去获取对象. 2 使用factory pattern的时机 第一,当一个对象的创建依赖于其它很多对象的时 ...

  7. vue项目目录

    项目目录说明 . |-- config                           // 项目开发环境配置 |   |-- index.js                     // 项目 ...

  8. 深入 JavaScript 中的对象以及继承原理

    ES6引入了一个很甜的语法糖就是 class, class 可以帮助开发者回归到 Java 时代的面向对象编程而不是 ES5 中被诟病的面向原型编程. 我也在工作的业务代码中大量的使用 class, ...

  9. Python菜鸟之路:Python基础-类(2)——成员、成员修饰符、异常及其他

    三大成员 在Python的面向对象中,主要包括三大成员:字段.方法.属性 字段 类成员的字段又可分为普通字段.静态字段,他们在定义和使用中有所区别,而最本质的区别是内存中保存的位置不同,代码示例如下: ...

  10. Bootstrap导航栏头部错位问题

    代码: <section class="header"> <div class="container"> <div class=& ...