传送门: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. java---迭代器(Iterator)

    迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的Iterator功能比较简单, ...

  2. vector中数据进行去重和排序

    , , , , , , ,}; std::vector<int> vec(a, a+sizeof(a)/sizeof(int) ); std::sort(vec.begin(), vec. ...

  3. ADO.NET中DataSet、DataTable、DataRow的数据复制方法

    DataSet 对象是支持 ADO.NET的断开式.分布式数据方案的核心对象 ,用途非常广泛.我们很多时候需要使用其中的数据,比如取得一个DataTable的数据或者复制另一个DataTabe中的数据 ...

  4. codeforces 987 D. Fair

    D. Fair time limit per test 2 seconds memory limit per test 512 megabytes input standard input outpu ...

  5. Django 2.0 学习(06):Django 视图(进阶)

    概述 Django中的特方法,该方法代表了Django的Web页面,并且视图具有特定的模板.以博客应用为例进行说明,在博客应用中应该包含下面的视图: 博客主页:显示最近的一些记录: 详细页面:单个详细 ...

  6. Tensorflow框架初尝试————搭建卷积神经网络做MNIST问题

    Tensorflow是一个非常好用的deep learning框架 学完了cs231n,大概就可以写一个CNN做一下MNIST了 tensorflow具体原理可以参见它的官方文档 然后CNN的原理可以 ...

  7. 具体数学数论章-----致敬Kunth

    整除性(divisible): 引入了代表整除性. m\n (m|n) 表示m整除n.注意这里的整除.表示的是n = km(k为整数). 在整除性这里.m必须是个正数.也许你可以描述n 是 m 的k倍 ...

  8. POJ1236:Network of Schools——题解

    http://poj.org/problem?id=1236 首先还是缩点,然后入度为0的点的个数就是你要投文件个数. 然后我们对于入度和出度为0的点的个数取最大值即为答案. (简单证明:入度和出度为 ...

  9. IT英语累积

    JPA: Java Persistence API   一种持久化规范 Spring Data:一种用于简化数据库访问,支持云服务的开源框架 Spring Data JPA:是Spring Data的 ...

  10. MySQL基础原创笔记(二)

    表索引关键字:PRI primary key 表示主键,唯一 写法: id bigint(20) unsigned primary key not null ,uni UNIQUE 表示唯一 id b ...