bzoj5311: 贞鱼
还是年轻啊算的时候少乘一个4000被卡二分上界了。。。%%%%bright教我超级快速读D飞bzoj垃圾卡常数据
我们容易写出这样的DP方程:f[i][j]=f[k][j-1]+val(k+1,j)
然后可以发现g(j)是单调减而且是下凸的
那么我们就可以愉快的上wqs二分了
那么f[i]就表示无限分最优解,就有f[i]=f[j]+val(j+1,i)+C
而这个明显是四边形不等式优化的形式
O(nlognlogw)踩了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL; const int MAXSIZE=<<;
char buf[MAXSIZE],*p1=buf,*p2=buf;
#define gc p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin),p1==p2)?EOF:*p1++
int read()
{
int x=,f=;char ch=gc;
while(ch<''||ch>''){if(ch=='-')f=-;ch=gc;}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=gc;}
return x*f;
} int n,s[][];
int val(int j,int i){return (s[i][i]-s[i][j]-s[j][i]+s[j][j])/;}
struct node
{
int l,r,id;
node(){}
node(int L,int R,int ID){l=L;r=R;id=ID;}
}q[];int f[],g[];
void check(int C)
{
int h=,t=;q[++t]=node(,n,);
f[]=;g[]=;
for(int i=;i<=n;i++)
{
if(q[h].r<i)h++;
q[h].l=i;
f[i]=f[q[h].id]+val(q[h].id,i)+C;
g[i]=g[q[h].id]+; if(h>t||f[i]+val(i,n)<=f[q[t].id]+val(q[t].id,n))
{
while(h<=t&&f[i]+val(i,q[t].l)<=f[q[t].id]+val(q[t].id,q[t].l))t--;
if(h>t)q[++t]=node(,n,i);
else
{
int l=q[t].l,r=q[t].r,ans;
while(l<=r)
{
int mid=(l+r)/;
if(f[i]+val(i,mid)>f[q[t].id]+val(q[t].id,mid))
{
ans=mid;
l=mid+;
}
else r=mid-;
}
q[t].r=ans;
q[++t]=node(ans+,n,i);
}
}
}
}
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
int K;
n=read(),K=read();
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
s[i][j]=read();
s[i][j]+=s[i-][j]+s[i][j-]-s[i-][j-];
} int l=,r=(<<)-,ans;
while(l<=r)
{
int mid=(l+r)/;
check(mid);
if(g[n]>=K)
{
ans=f[n]-K*mid;
l=mid+;
}
else r=mid-;
}
printf("%d\n",ans);
return ;
}
bzoj5311: 贞鱼的更多相关文章
- BZOJ5311 贞鱼(动态规划+wqs二分+决策单调性)
大胆猜想答案随k变化是凸函数,且有决策单调性即可.去粘了份fread快读板子才过. #include<iostream> #include<cstdio> #include&l ...
- [CF321E]Ciel and Gondolas&&[BZOJ5311]贞鱼
codeforces bzoj description 有\(n\)个人要坐\(k\)辆车.如果第\(i\)个人和第\(j\)个人同坐一辆车,就会产生\(w_{i,j}\)的代价. 求最小化代价.\( ...
- 【BZOJ5311/CF321E】贞鱼/Ciel and Gondolas(动态规划,凸优化,决策单调性)
[BZOJ5311/CF321E]贞鱼/Ciel and Gondolas(动态规划,凸优化,决策单调性) 题面 BZOJ CF 洛谷 辣鸡BZOJ卡常数!!!!!! 辣鸡BZOJ卡常数!!!!!! ...
- BZOJ5311,CF321E 贞鱼
题意 Problem 5311. -- 贞鱼 5311: 贞鱼 Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 677 Solved: 150[Subm ...
- ROJ 1166 超级贞鱼
1166: 超级贞鱼 Time Limit: 1 Sec Memory Limit: 128 MB [Submit][Status] 传送门 Description 马达加斯加贞鱼是一种神奇的双脚贞 ...
- 【Codeforces 321E / BZOJ 5311】【DP凸优化】【单调队列】贞鱼
目录 题意: 输入格式 输出格式 思路: DP凸优化的部分 单调队列转移的部分 坑点 代码 题意: 有n条超级大佬贞鱼站成一行,现在你需要使用恰好k辆车把它们全都运走.要求每辆车上的贞鱼在序列中都是连 ...
- bzoj 4769: 超级贞鱼 -- 归并排序
4769: 超级贞鱼 Time Limit: 1 Sec Memory Limit: 128 MB Description 马达加斯加贞鱼是一种神奇的双脚贞鱼,它们把自己的智慧写在脚上——每只贞鱼的 ...
- 【BZOJ4769】超级贞鱼 归并排序求逆序对
[BZOJ4769]超级贞鱼 Description 马达加斯加贞鱼是一种神奇的双脚贞鱼,它们把自己的智慧写在脚上——每只贞鱼的左脚和右脚上各有一个数.有一天,K只贞鱼兴致来潮,排成一列,从左到右第i ...
- 贞鱼传教&&贞鱼传教(数据加强版)
http://acm.buaa.edu.cn/problem/1381/ 贞鱼传教[问题描述] 新的一年到来了,贞鱼哥决定到世界各地传授“贞教”,他想让“贞教”在2016年成为世界第四大宗教.说干就干 ...
随机推荐
- 树莓派 - 驱动hello
树莓派上Linux驱动,从hello world 开始 ... hello.c #include <linux/init.h> #include <linux/module.h> ...
- RNN与情感分类问题实战-加载IMDB数据集
目录 Sentiment Analysis Two approaches Single layer Multi-layers Sentiment Analysis Two approaches Sim ...
- IDEA 2018集成MyBatis Generator 插件 详解
1.修改maven的pom文件 只需要将如下依赖添加到pom.xml文件中即可.(注意此处是以plugin的方式,放在<plugins> </plugins>中间即可) < ...
- 开发调式时生成dump文件
开发调式时,对程序生成dump文件:1:需要生成的时机,加Thread.sleep(600*1000).2:打开jvisualvm找到该程序进程号.3:jmap.
- 关于zookeeper中session timeout
转自https://yq.aliyun.com/articles/117825?t=t1,主要结论如下: 经过源码分析,得出SessionTimeOut的协商如下: 情况1: 配置文件配置了maxSe ...
- jQuery调用WCF 说明
在项目中用过一些WCF的技术这篇文章是对以前用过的一点东西的一个梳理 一,webconfig的配置除了一般的配置外,与WCF相关的配置如下 <system.serviceModel> ...
- PowerShell Tools for Visual Studio 2015
首先要去下载Visual Studio 2015 RC 版本 https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downl ...
- About SQL Server 2016 CPT2
SQL Server 2016 CTP2已经发布,可以从以下主页进行下载. http://www.microsoft.com/en-us/server-cloud/products/sql-serve ...
- hihoCoder#1082 然而沼跃鱼早就看穿了一切
原题地址 字符串匹配+替换 注意替换串和原串长度是不等的,所以替换完还要进行收缩 可以顺带练习一下KMP 代码: #include <iostream> #include <cstr ...
- hdu 2433 Travel (最短路树)
One day, Tom traveled to a country named BGM. BGM is a small country, but there are N (N <= 100) ...