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$的子正方形翻转 翻转的意义为该区域里的数都变成原来的相反数. ...
随机推荐
- ChromeSwitchySharp代理设置步骤
步骤: 1.新增情景模式配置如下: 2.设置切换规则 3.先“直接连接”进行登录:然后切换到“自动切换模式”访问对应url
- Java 类和Static关键字
类的定义 类的命名.首字母大写 大括号后面没有分号 成员变量 Java会自动初始化成员变量但是不会自动初始化局部变量: 可以在定义成员变量是直接初始化,成员变量的作用范围在整个类体 对象的创建和引用的 ...
- OSG学习:使用已有回调示例
回调的类型有很多种,一般很容易就想到的是UpdateCallBack,或者EventCallBack,回调的意思就是说,你可以规定在某件事情发生时启动一个函数,这个函数可能做一些事情.这个函数就叫做回 ...
- CentOs7.3 搭建 Redis-4.0.1 Cluster 集群服务
环境 VMware版本号:12.0.0 CentOS版本:CentOS 7.3.1611 三台虚拟机(IP):192.168.252.101,192.168.102..102,192.168.252. ...
- Windows Server 2012四大版本介绍
今天刚好要尝试安装Windows Server 2012,在网上百度了下发现有4个版本,分别是: Datacenter数据中心版. Standard标准版. Essentials版. Foundati ...
- 文件上传C:\fakepath\解决方案
1.设置IE:工具 -> Internet选项 -> 安全 -> 自定义级别 -> 找到“其他”中的“将本地文件上载至服务器时包含本地目录路径”,选中“启用”即可 2.利用js ...
- BZOJ 1797 最小割(最小割割边唯一性判定)
问题一:是否存在一个最小代价路径切断方案,其中该道路被切断? 问题二:是否对任何一个最小代价路径切断方案,都有该道路被切断? 现在请你回答这两个问题. 最小割唯一性判定 jcvb: 在残余网络上跑ta ...
- 新浪云部署java web程序 注意事项
在新浪云新手指南里有部署java的示例,但是对一个新手来说难免会有一些地方犯错,折腾了好长时间才把自己的java web部署到了新浪云.这里主要写一些我遇到的问题与第一次使用新浪云的朋友分享一下. 首 ...
- poj 1273 && hdu 1532 Drainage Ditches (网络最大流)
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53640 Accepted: 2044 ...
- CF961D Pair Of Lines
题目描述 You are given n n n points on Cartesian plane. Every point is a lattice point (i. e. both of it ...