DP优化/四边形不等式


  这题……跟邮局那题简直一模一样吧……好水的E题……

  设dp[i][j]表示前 i 艘“gondola”坐了前 j 个人,那么方程即为$dp(i,j)=min\{ dp[i-1][k]+w[k][j] \} (i\leq k\leq j)$

  很明显$w(l,r)=\sum_{i=l}^r \sum_{j=l}^r u(i,j) /2$是满足四边形不等式的……那么根据决策单调性直接搞就行了……

 //CF 321E
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
//#define debug
int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<='') {v=v*+ch-''; ch=getchar();}
return v*sign;
}
typedef long long LL;
const int N=,INF=~0u>>;
/*******************tamplate********************/
LL u[][],n,m,w[][],dp[][];
int s[][];
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
n=getint(); m=getint();
F(i,,n) F(j,,n) u[i][j]=getint();
F(i,,n) F(j,,n) u[i][j]+=u[i-][j]+u[i][j-]-u[i-][j-]; F(i,,n) F(j,i+,n) w[i][j]=u[j][j]-u[i-][j]-u[j][i-]+u[i-][i-]; #ifdef debug
F(i,,n) {F(j,,n) printf("%3d",w[i][j]);puts("");}
#endif
F(i,,m) F(j,,n) dp[i][j]=INF;
F(i,,n){
dp[][i]=w[][i];
s[][i]=;
}
F(i,,m){
s[i][n+]=n;
D(j,n,i)
F(k,s[i-][j],s[i][j+])
if (dp[i-][k]+w[k+][j]<dp[i][j]){
s[i][j]=k;
dp[i][j]=dp[i-][k]+w[k+][j];
}
}
printf("%I64d\n",dp[m][n]/);
return ;
}

【CodeForces】【321E】Ciel and Gondolas的更多相关文章

  1. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  2. 【Codeforces Round #438 C】 Qualification Rounds

    [链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...

  3. 【Codeforces Round #438 B】Race Against Time

    [链接]h在这里写链接 [题意] 时针.分钟.秒针走不过去. 问你从t1时刻能不能走到t2时刻 [题解] 看看时针.分钟.秒针的影响就好. 看看是不是在整时的位置就好. 然后看看影响到x不能到y; 然 ...

  4. 【Codeforces Round #438 A】Bark to Unlock

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...

  5. 【codeforces 718 C&D】C. Sasha and Array&D. Andrew and Chemistry

    C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$o ...

  6. 【codeforces contest 1119 F】Niyaz and Small Degrees

    题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...

  7. 【codeforces #282(div 1)】AB题解

    A. Treasure time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

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

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

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  10. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

随机推荐

  1. Thinkphp 下面执行crond

    thinkphp开启cli支持  1.tp正好支持cli命令模式,手册的路径为13.7.4 如果是用的其他框架不支持cli,那么只能直接写程序了,其实就是写面向过程的最基础的php代码. 2.在入口文 ...

  2. Nginx配置:http重定向,URLRewrite,一个简单框架的配置思路

    一个重定向的应用配置: server { listen       8000; server_name  localhost; root F:/home/projects/test; index   ...

  3. Flex 4.0及4.6发布的网络应用在内网内会访问很慢的解决方案

    Flex 4.x 开发的程序部署在外网在能访问到www.adobe.com的时能够很快加载完成,但是部署在本地局域网,不能访问外网的服务器上,用浏览器访问应用需要加载几分钟的时间,这种等待时间客户几乎 ...

  4. 1)Java JDK和JRE

    >JRE :  Java Runtime Enviroment   Java的运行环境.面向Java程序的使用者,而不是开发者.如果你仅下载并安装了JRE,那么你的系统只能运行Java程序(不能 ...

  5. Java4Android

    变量 在计算机中存储信息需要声明变量的位置和所需的内存空间 boolean true false char ASCII字符集 计算机中所有数据都使用二进制表示 例如:a,b,c 适用七位二进制数进行表 ...

  6. PropertyGrid 控件使用方法

    编写一个对象,后面传递给 PropertyGrid 来显示: using System; using System.Collections.Generic; using System.Linq; us ...

  7. video 测试

    https://segmentfault.com/a/1190000002401961  音量调节https://www.google.com/?gws_rd=ssl#newwindow=1& ...

  8. DrawTool多重笔之前奏 => 通过InkAnalyzer实现图形识别

    这里要介绍的是通过InkAnalyzer来实现简单图形的识别,例如圆,椭圆,正方形,三角形等,当然你也可以通过扩展来实现自定义图形的识别,在使用InkAnalyzer前,你需要引用IAWinFX.dl ...

  9. 1008. Elevator (20)

    The highest building in our city has only one elevator. A request list is made up with N positive nu ...

  10. oracle 修改表空间存储路径

    [root@yoon ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 Oracle Database 11g Enterpris ...