[BALTIC 2008] Grid
[题目链接]
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的更多相关文章
- 洛谷 P4660 & bzoj 1168 [ Baltic OI 2008 ] 手套 —— 分析+单调栈
题目:https://www.luogu.org/record/show?rid=12702916 https://www.lydsy.com/JudgeOnline/problem.php?id=1 ...
- 为WPF和Silverlight的Grid添加边框线(zz)
Grid是WPF和Silverlight中的一个重要的布局元素,其他的布局元素还有StackPanel, Canvas, Border等等.从字面上说,Grid是一个表格的意思,它的使用也确实很方 ...
- 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 ...
- Oracle RAC集群安装之:Grid软件安装过程蓝屏
前几天在安装一套RAC服务器的过程中,遇到了蓝屏事件,折腾了蛮久(在排查是否存在硬件问题上花费了相当多一部分时间),整个过程大概说明如下: 1.两台华为的PC SERVER,操作系统为WIN SERV ...
- jQuery的几个Grid插件简单比较
目标:实现一个类似于Excel功能的Grid数据维护功能,并且就地编辑在乎的是Cell编辑而不是行编辑 候选者:easy-ui之datagrid, jqgrid, flexigrid 使用环境:jqu ...
- SQL Server 2008空间数据应用系列十二:Bing Maps中呈现GeoRSS订阅的空间数据
原文:SQL Server 2008空间数据应用系列十二:Bing Maps中呈现GeoRSS订阅的空间数据 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Se ...
- 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 操作系 ...
- 重新想象 Windows 8 Store Apps (7) - 控件之布局控件: Canvas, Grid, StackPanel, VirtualizingStackPanel, WrapGrid, VariableSizedWrapGrid
原文:重新想象 Windows 8 Store Apps (7) - 控件之布局控件: Canvas, Grid, StackPanel, VirtualizingStackPanel, WrapGr ...
- 背水一战 Windows 10 (38) - 控件(布局类): Panel, Canvas, RelativePanel, StackPanel, Grid
[源码下载] 背水一战 Windows 10 (38) - 控件(布局类): Panel, Canvas, RelativePanel, StackPanel, Grid 作者:webabcd 介绍背 ...
随机推荐
- Linux 服务器上建立用户并分配权限
查看用户 whoami #要查看当前登录用户的用户名 who am i #表示打开当前伪终端的用户的用户名 who mom likes who 命令其它常用参数 参数 说明 -a 打印能打印的全部 - ...
- web.xml配置中的log4jRefreshInterval
采用spring框架的项目如何使用log4j在spring中使用log4j,有些方便的地方, 1.动态的改变记录级别和策略,即修改log4j.properties,不需要重启web应用,这需要在web ...
- GridView 显示行号 设置行号列的宽度
/// <summary> /// GridView 显示行号 设置行号列的宽度 /// </summary> /// <param name="gv" ...
- 九度OJ 1324:The Best Rank(最优排名) (排序)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:489 解决:126 题目描述: To evaluate the performance of our first year CS major ...
- css3 transition效果
<meta charset="UTF-8"> <style> .btn { display: inline-block; font-size: 12px; ...
- CF451E Devu and Flowers(容斥)
CF451E Devu and Flowers(容斥) 题目大意 \(n\)种花每种\(f_i\)个,求选出\(s\)朵花的方案.不一定每种花都要选到. \(n\le 20\) 解法 利用可重组合的公 ...
- [Java面试一]Spring总结以及在面试中的一些问题.(转发:http://www.cnblogs.com/wang-meng/p/5701982.html)
1.谈谈你对spring IOC和DI的理解,它们有什么区别? IoC Inverse of Control 反转控制的概念,就是将原本在程序中手动创建UserService对象的控制权,交由Spri ...
- C#窗体互动
说白了就是在一个窗体操作另外一个窗体的东西. 原理是把form2的数据提取出来,利用中间的静态类middle来传递数据,触发事件,调用委托,来修正form1 效果如下: Form1.cs usin ...
- ICCV 2015 B-CNN细粒度分类
哈哈,好久没写博客了....最近懒癌发作~~主要是因为心情不太好啊,做什么事情都不太顺心,不过已经过去啦.最近一直忙着公司的项目,想用这个网络,就给大家带来了的这篇文章.可能比较老,来自ICCV 20 ...
- Linux:进程管理
Linux:进程管理 进程间通信 文件和记录锁定. 为避免两个进程间同时要求访问同一共享资源而引起访问和操作的混乱,在进程对共享资源进行访问前必须对其进行锁定,该进程访问完后再释放.这是UNIX为共享 ...