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$的子正方形翻转 翻转的意义为该区域里的数都变成原来的相反数. ...
随机推荐
- c# 四则运算出错
不同类型值之间不可直接相减,long和short得出的差继续参与运算出错. 有待深究.
- Debian 7 amd64 + fbterm + ucimf
前段时间,显示器出了问题,导致Debian下只有终端显示正常,桌面显示效果很是摇晃模糊.遂起了念头,能不能在终端下就能完成日常的工作. google了很久,终于知道fbterm可以在终端下显示中文,加 ...
- SQL 跨库查询
使用SQL查询数据,不仅能查询当前库的数据,还可以跨数据库,甚至跨服务器查询. 下面给大家介绍一下跨服务器查询的步骤(以SQL Server为例): 1,建立数据库链接 EXEC sp_addlink ...
- 3dContactPointAnnotationTool开发日志(八)
今天上午去实验室打算把项目从github上pull下来发现貌似不行,然后强行pull下来后项目变得乱七八糟了,有的组件都不知道去哪里了.去github上看了看发现上面day6和day7都没有,特别 ...
- Activemq 消息类型 (转)
Activemq消息类型JMS规范中的消息类型包括TextMessage.MapMessage.ObjectMessage.BytesMessage.和StreamMessage等五种.ActiveM ...
- jCanvaScript canvas的操作库
在jcscript.com上下载最新的jCanvaScript.1.5.18.min.js文件 里面有很多关于canvas的方法都已经是封装好了的,只需直接调用,但是要注意调用之前和调用之后都要写: ...
- 【Todo】【转载】JVM学习
先参考如下这个系列<聊聊JVM> http://blog.csdn.net/column/details/talk-about-jvm.html
- 在Linux上编译TCMalloc
TCMalloc(Thread-Caching Malloc)与标准glibc库的malloc实现一样的功能,但是TCMalloc在效率和速度效率都比标准malloc高很多.TCMalloc是goog ...
- [CF622F]The Sum of the k-th Powers
题目大意:给你$n,k(n\leqslant10^9,k\leqslant10^6)$,求:$$\sum\limits_{i=1}^ni^k\pmod{10^9+7}$$ 题解:可以猜测是一个$k+1 ...
- 洛谷 U32911 道路维护 解题报告
U32911 道路维护 题目背景 最近很多人投诉说C国的道路破损程度太大,以至于无法通行. C国的政府很重视这件事,但是最近财政有点紧,不可能将所有的道路都进行维护,所以他们决定按照下述方案进行维护. ...