对拍了一波才找到的错误,此题我用的是二分答案加倍增查询,实际上query那里我觉得仍然有缺陷,因为每一次我的查找还是在循环找到一个k使得x+2^k <= y,而错的地方也正在此地,一开始没有判断x+2^k > y,反而直接将k=y的二进制下的最大的为1的位置,以后一定要注意边界条件。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 2005
#define ull unsigned long long
#define ll long long
#define hashmod 99999839
#define mod 9997
int a[maxn];
int dp[maxn][],p[];
int n,k;
//dp(i,j) 表示区间[i,i+2^j]中的最大值
//dp(i,j) = max(dp(i,j-1),dp(i+2^(j-1),j-1);
//dp(i,j) = max(dp(i,j-1),q(i+2^(j-1)+1,i+2^j));
//如果查询[x,y]中的最大值则q(x,y) = max(dp(x,k),q(x+2^k+1,y)),x+2^k <= y,k <= log(y-x)
int bitsearch(int x){
int l = ,r = ,mid,ans;
while(l <= r){
mid = (l+r)>>;
if(p[mid] > x) r = mid - ;
else l = mid + ,ans = mid;
}
return ans;
}
int query(int x,int y){
if(x > y) return ;
if(x == y) return a[x];
int k = bitsearch(y);
while(x + p[k] > y) k--;
return max(dp[x][k],query(x+p[k]+,y));
}
bool judge(int m){
int t = n / m,sum = ;
for(int i = ;i <= t * m;i += t){
sum += query(i,i+t-);
}
if(sum > k) return true;
return false;
}
void init(){
p[] = ;
for(int i = ;i <= ;++i) p[i] = p[i - ] << ;
}
int main(){
// freopen("a.in","r",stdin);
// freopen("b.out","w",stdout);
init();
while(~scanf("%d%d",&n,&k)){
if(n < && k < ) break;
memset(dp,,sizeof(dp));
int Max = ;
for(int i = ;i <= n;++i) scanf("%d",&a[i]),dp[i-][] = max(a[i-],a[i]),Max = max(Max,a[i]);
dp[n][] = a[n];
int li = bitsearch(n) + ;
for(int j = ;j <= li;++j){
for(int i = ;i <= n;++i){
if(i + p[j] > n){
if(i + p[j - ] <= n) dp[i][j] = max(dp[i][j-],dp[i+p[j-]][j-]);
else dp[i][j] = dp[i][j-];
continue;
}
dp[i][j] = max(dp[i][j-],dp[i+p[j-]][j-]);
}
}
int l = ,r = n,mid,ans = -;
while(l <= r){
mid = (l + r) >> ;
if(judge(mid)){
ans = mid;
r = mid - ;
}
else l = mid + ;
}
printf("%d\n",ans);
}
return ;
}

csu1364 Interview的更多相关文章

  1. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  2. WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】

    http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...

  3. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  4. Amazon Interview | Set 27

    Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...

  5. Java Swing interview

    http://www.careerride.com/Swing-AWT-Interview-Questions.aspx   Swing interview questions and answers ...

  6. Pramp - mock interview experience

    Pramp - mock interview experience   February 23, 2016 Read the article today from hackerRank blog on ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. [译]Node.js Interview Questions and Answers (2017 Edition)

    原文 Node.js Interview Questions for 2017 什么是error-first callback? 如何避免无止境的callback? 什么是Promises? 用什么工 ...

  9. WCF学习系列三--【WCF Interview Questions – Part 3 翻译系列】

    http://www.topwcftutorials.net/2012/10/wcf-faqs-part3.html WCF Interview Questions – Part 3 This WCF ...

随机推荐

  1. 工厂方法模式及php实现

    工厂方法模式: 工厂方法模式(Factory Method Pattern)又称为工厂模式,也叫虚拟构造器(Virtual Constructor)模式或者多态工厂(Polymorphic Facto ...

  2. 后缀数组 (Suffix Array) 学习笔记

    \(\\\) 定义 介绍一些写法和数组的含义,首先要知道 字典序 . \(len\):字符串长度 \(s\):字符串数组,我们的字符串存储在 \(s[0]...s[len-1]\) 中. \(suff ...

  3. 坑爹的鲁大师,VMware Workstation 报错(AsyncSocket error)一例解决

    今天准备把电脑上安装的VMware Play换成VMware Workstation,毕竟 Workstation 的快照功能还是很有必要的. 结果,VMware Workstation 安装成功后, ...

  4. Android 重定向 init.rc中服务的输出

    在init.rc中运行的服务,由于系统启动的时候将标准输出重定向到了/dev/null, 所以服务中的打印信息都不可见. 但调试时可能需要看到其中的打印信息,因此就有了logwrapper这个工具:l ...

  5. ArrayList源码分析(基于JDK1.8)

    public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess ...

  6. Java入门第39课——猜字母游戏之实现字母生成方法

    问题        实现猜字母游戏中的字母生成方法,即,随机生成5个不同的字母作为猜测的结果. 方案        实现generate方法,首先声明一个字符类型的数组,用于存储26个大写字母,然后声 ...

  7. 数据库和java的类型转化

    mysql 的转化 count(1)   返回类型是bigint  对应的java 是 BigInteger cast(sum(name) as char)    sum转化为字符串

  8. AutoIt简单使用

    以上是自己在公司做培训的PPT首页,其实在线的中文参考文档很全面,很值得学习的.

  9. 用npm来部署快速一个httpweb服务器

    https://blog.csdn.net/u012182627/article/details/55060594 http-server的安装######注意事项 安装http-server的时候 ...

  10. AUSU 安装Win10注意事项

    Win10 U盘原版安装 安装前在电脑店PE里用DiskGenius分区分区表类型:GUID勾选:创建新ESP分区 . 创建MSR分区 安装必须使用UEFI引导和GPT硬盘,否则会提示无法安装Win1 ...