传送门: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的更多相关文章

  1. 【BZOJ5311/CF321E】贞鱼/Ciel and Gondolas(动态规划,凸优化,决策单调性)

    [BZOJ5311/CF321E]贞鱼/Ciel and Gondolas(动态规划,凸优化,决策单调性) 题面 BZOJ CF 洛谷 辣鸡BZOJ卡常数!!!!!! 辣鸡BZOJ卡常数!!!!!! ...

  2. Codeforces G. Ciel the Commander

    题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input stan ...

  3. CF321E Ciel and Gondolas Wqs二分 四边形不等式优化dp 决策单调性

    LINK:CF321E Ciel and Gondolas 很少遇到这么有意思的题目了.虽然很套路.. 容易想到dp \(f_{i,j}\)表示前i段分了j段的最小值 转移需要维护一个\(cost(i ...

  4. 【CodeForces】【321E】Ciel and Gondolas

    DP优化/四边形不等式 这题……跟邮局那题简直一模一样吧……好水的E题…… 设dp[i][j]表示前 i 艘“gondola”坐了前 j 个人,那么方程即为$dp(i,j)=min\{ dp[i-1] ...

  5. CodeForces - 321E:Ciel and Gondolas (四边形不等式优化DP)

    题意:N个人排成一行,分成K组,要求每组的不和谐值之和最小. 思路:开始以为是斜率优化DP,但是每个区间的值其实已经知道了,即是没有和下标有关的未知数了,所以没必要用斜率. 四边形优化. dp[i][ ...

  6. 【23.58%】【code forces 321E】Ciel and Gondolas

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  7. CodeForces 321C Ciel the Commander

    Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...

  8. [CF321E]Ciel and Gondolas&&[BZOJ5311]贞鱼

    codeforces bzoj description 有\(n\)个人要坐\(k\)辆车.如果第\(i\)个人和第\(j\)个人同坐一辆车,就会产生\(w_{i,j}\)的代价. 求最小化代价.\( ...

  9. Codeforces 321D Ciel and Flipboard(结论题+枚举)

    题目链接   Ciel and Flipboard 题意  给出一个$n*n$的正方形,每个格子里有一个数,每次可以将一个大小为$x*x$的子正方形翻转 翻转的意义为该区域里的数都变成原来的相反数. ...

随机推荐

  1. Ubuntu下FileZilla的安装

    FileZilla是一个免费而且开源的FTP客户端软件,共有两种版本:客户端版本.服务器版本.FileZilla有条理的界面和管理多站点的简化方式使得FileZilla Client成为一个方便高效的 ...

  2. <Android>spinner/AutoCompleteTextView绑定适配器

    position = (Spinner)findViewById(R.id.position); String[] str = {"CEO","CFO",&qu ...

  3. c++设计模式----装饰模式

    前言 在实际开发时,你有没有碰到过这种问题:开发一个类,封装了一个对象的核心操作,而这些操作就是客户使用该类时都会去调用的操作:而有一些非核心的操作,可能会使用,也可能不会使用:现在该怎么办呢? 将这 ...

  4. C# WebBrowser控件详解

     作者:827969653     0.常用方法 Navigate(string urlString):浏览urlString表示的网址 Navigate(System.Uri url):浏览url表 ...

  5. ubuntu下修改MySQL的配置文件my.cnf

    先sudo su转换成root,再用cd转到/etc/MySQL目录下,用chmod修改权限(chmod 755 my.cnf),但这样还不能修改,再用vi命令(vi my.cnf),通过上下方向键将 ...

  6. animate.css与wow.js制作网站动效

    animate.css 官网:https://daneden.github.io/animate.css/ 包括:attention seekers:关注者 bouncing entrances:跳跃 ...

  7. 在html在添加cookie和读取cookie

    1.保存cookie var oDate = new Date(); oDate.setDate(oDate.getDate() + );//有效期为30天 document.cookie = &qu ...

  8. Java调用WebService之Axis实现

    import org.apache.axis.client.Call; import org.apache.axis.client.Service; /** * @ClassName: TestAxi ...

  9. BZOJ 1057 棋盘制作(最大01相间子矩阵)

    求最大01相间子矩阵可以转换为求最大全0子矩阵.只需把棋盘(x+y)为奇数的取反,而该问题可以用经典的悬线法O(n^2)的求解. 悬线法呢. 首先定义b[i][j],为a[i][j]向上的最大连续0的 ...

  10. Luogu1731 NOI1999生日蛋糕(搜索)

    非常经典的剪枝题然而一直没有写.感觉自己连普及组水平都没有了. 1.半径和高枚举范围满足加上后总体积不超过n且剩下每层还能放. 2.半径从大到小枚举,因为体积正比于半径平方而面积正比于半径,大的半径更 ...