Codeforces 321E Ciel and Gondolas
传送门:http://codeforces.com/problemset/problem/321/E
【题解】
首先有一个$O(n^2k)$的dp。
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + , N = + ;
const int mod = 1e9+;
const ll inf = 1e17; inline int getint() {
int x = ; char ch = getchar();
while(!isdigit(ch)) ch = getchar();
while(isdigit(ch)) x = (x<<) + (x<<) + ch - '', ch = getchar();
return x;
} int n, K, a[N][N], d[N][N];
ll f[][N]; int main() {
n = getint(), K = getint();
for (int i=; i<=n; ++i)
for (int j=; j<=n; ++j)
a[i][j] = a[i-][j] + a[i][j-] - a[i-][j-] + getint();
for (int i=; i<=n; ++i) {
d[i][i] = ;
for (int j=i+; j<=n; ++j)
d[i][j] = (a[j][j] - a[j][i-] - a[i-][j] + a[i-][i-])/;
}
for (int i=; i<=n; ++i) f[][i] = inf;
for (int i=; i<=K; ++i) {
for (int j=; j<=n; ++j) {
f[i][j] = inf;
for (int k=; k<j; ++k)
f[i][j] = min(f[i][j], f[i-][k] + d[k+][j]);
}
}
cout << f[K][n]; return ;
}
然后发现每层当n向右移动的时候,决策点一定向右移动
(可能可以观察+证明)
然后用整体二分trick就可以了。复杂度$O(Knlogn)$。
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + , N = + ;
const int mod = 1e9+;
const ll inf = 1e17; inline int getint() {
int x = ; char ch = getchar();
while(!isdigit(ch)) ch = getchar();
while(isdigit(ch)) x = (x<<) + (x<<) + ch - '', ch = getchar();
return x;
} int n, K, a[N][N], d[N][N];
ll f[][N], *F, *G; inline void solve(int l, int r, int al, int ar) {
if(l > r) return ;
int mid = l+r>>; ll mx = inf, t; int pos = ;
for (int j=al; j<=ar && j<mid; ++j)
if((t = G[j] + d[j+][mid]) < mx) mx = t, pos = j;
F[mid] = mx;
solve(l, mid-, al, pos);
solve(mid+, r, pos, ar);
} int main() {
n = getint(), K = getint();
for (int i=; i<=n; ++i)
for (int j=; j<=n; ++j)
a[i][j] = a[i-][j] + a[i][j-] - a[i-][j-] + getint();
for (int i=; i<=n; ++i) {
d[i][i] = ;
for (int j=i+; j<=n; ++j)
d[i][j] = (a[j][j] - a[j][i-] - a[i-][j] + a[i-][i-])/;
}
for (int i=; i<=n; ++i) f[][i] = inf;
for (int i=; i<=K; ++i) {
F = f[i], G = f[i-];
solve(, n, , n);
}
cout << f[K][n]; return ;
}
Codeforces 321E Ciel and Gondolas的更多相关文章
- 【BZOJ5311/CF321E】贞鱼/Ciel and Gondolas(动态规划,凸优化,决策单调性)
[BZOJ5311/CF321E]贞鱼/Ciel and Gondolas(动态规划,凸优化,决策单调性) 题面 BZOJ CF 洛谷 辣鸡BZOJ卡常数!!!!!! 辣鸡BZOJ卡常数!!!!!! ...
- Codeforces G. Ciel the Commander
题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CF321E Ciel and Gondolas Wqs二分 四边形不等式优化dp 决策单调性
LINK:CF321E Ciel and Gondolas 很少遇到这么有意思的题目了.虽然很套路.. 容易想到dp \(f_{i,j}\)表示前i段分了j段的最小值 转移需要维护一个\(cost(i ...
- 【CodeForces】【321E】Ciel and Gondolas
DP优化/四边形不等式 这题……跟邮局那题简直一模一样吧……好水的E题…… 设dp[i][j]表示前 i 艘“gondola”坐了前 j 个人,那么方程即为$dp(i,j)=min\{ dp[i-1] ...
- CodeForces - 321E:Ciel and Gondolas (四边形不等式优化DP)
题意:N个人排成一行,分成K组,要求每组的不和谐值之和最小. 思路:开始以为是斜率优化DP,但是每个区间的值其实已经知道了,即是没有和下标有关的未知数了,所以没必要用斜率. 四边形优化. dp[i][ ...
- 【23.58%】【code forces 321E】Ciel and Gondolas
time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- CodeForces 321C Ciel the Commander
Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- [CF321E]Ciel and Gondolas&&[BZOJ5311]贞鱼
codeforces bzoj description 有\(n\)个人要坐\(k\)辆车.如果第\(i\)个人和第\(j\)个人同坐一辆车,就会产生\(w_{i,j}\)的代价. 求最小化代价.\( ...
- Codeforces 321D Ciel and Flipboard(结论题+枚举)
题目链接 Ciel and Flipboard 题意 给出一个$n*n$的正方形,每个格子里有一个数,每次可以将一个大小为$x*x$的子正方形翻转 翻转的意义为该区域里的数都变成原来的相反数. ...
随机推荐
- Linux上安装MySQL - 12条命令搞定MySql
从零开始安装mysql数据库 : 按照该顺序执行 : a. 查看是否安装有mysql:yum list installed mysql*, 如果有先卸载掉, 然后在进行安装; b. 安装mysql客 ...
- 解决python中文编码错误问题
对于初学者而言,编码问题或许还没有没重视起来,但是编码问题是中文开发者必须面对的.今天来看下python开发中如何解决编码问题.注意:本篇讲的是最常见的一种编码问题,其他编码问题,如json函数引起的 ...
- iOS开发多线程编程2 - NSOperation
1.简介 NSOperation实例封装了需要执行的操作和执行操作所需的数据,并且能够以并发或非并发的方式执行这个操作. NSOperation本身是抽象基类,因此必须使用它的子类,使用NSOpera ...
- PAT 甲级 1032 Sharing
https://pintia.cn/problem-sets/994805342720868352/problems/994805460652113920 To store English words ...
- 【Docker 命令】- rmi命令
docker rmi : 删除本地一个或多个镜像. 语法 docker rmi [OPTIONS] IMAGE [IMAGE...] OPTIONS说明: -f :强制删除: --no-prune : ...
- 完整和增量备份MySQL脚本
本文档采用mysqldump 对数据库进行备份,mysqldump 是采用SQL级别的备份机制,它将数据表导成 SQL脚本文件,在不同的 MySQL 版本之间升级时相对比较合适,这也是最常用的备份方法 ...
- mysql,oracle,sql server中的默认事务隔离级别查看,更改
未提交读(隔离事务的最低级别,只能保证不读取物理上损坏的数据) 已提交读(数据库引擎的默认级别) 可重复读 可序列化(隔离事务的最高级别,事务之间完全隔离) 可串行化比较严谨,级别高; MySQL m ...
- [OS] 多线程--第一次亲密接触CreateThread与_beginthreadex本质区别
转自:http://blog.csdn.net/morewindows/article/details/7421759 本文将带领你与多线程作第一次亲密接触,并深入分析CreateThread与_be ...
- BZOJ 1297 迷路(矩阵快速幂)
很容易想到记忆化搜索的算法. 令dp[n][T]为到达n点时时间为T的路径条数.则dp[n][T]=sigma(dp[i][T-G[i][n]]); 但是空间复杂度为O(n*T),时间复杂度O(n*n ...
- 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚 dp/线段树
题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...