对拍了一波才找到的错误,此题我用的是二分答案加倍增查询,实际上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. HTML标签,简单归纳

    列表标签 有序列表: <ol><li></li></ol> 无序列表: <ul><li></li></ul&g ...

  2. Toolbar自定义布局

    Toolbar如何使用想必大家清楚地很,实际开发中标题栏的样式各色各样,因此其基本样式便不能满足我们的需求,这就需要我们自定义布局.打开ToolBar源码我们发现它继承ViewGroup,这就表示我们 ...

  3. 关于react native在window下运行安卓的时候报 could not connect to development server

    当出现这种问题是网上的解答方案都是一模一样的! 我这边先给个地址讲的是解决方案http://blog.csdn.net/qq_25827845/article/details/52974991 但是我 ...

  4. Selenium--Python环境部署

    本文引读:一二为python环境安装:三为selenium安装同时介绍了pip:四为PyCharm安装:五为验证SE可以正常使用 一.下载python安装包 我这里安装的是python3.6.5,官网 ...

  5. Objective -C Object initialization 对象初始化

    Objective -C Object initialization 对象初始化 1.1 Allocating Objects  分配对象 Allocation is the process by w ...

  6. iOS---iOS中SQLite的使用

    一.SQLite的使用 采用SQLite数据库来存储数据.SQLite作为一中小型数据库,应用ios中,跟前三种保存方式相比,相对比较复杂一些.还是一步步来吧! 第一步:导入头文件 需要添加SQLit ...

  7. 开源一个一个NodeJS 代理服务器扫描工具,可以用来***

    鉴于我朝很多网站访问不了,google等就是大悲剧,之前一直在用VPN,但是公司内网VPN被封,诸多工具也惨遭毒手..我辈怎能容忍. 目前只有代理没有被封,于是搞了个代理扫描工具并开源: https: ...

  8. mathAge.call(btn) 函数call 改变函数内 this #js

    mathAge.call(btn) 函数call 改变函数内 this

  9. vue工程化:返回顶部和底部的动画效果

    . <template> <div> <div class="scroll" :class="{show:isActive}"&g ...

  10. Django中使用多线程发送邮件

    1.settings.py 增加Email设置   #mail EMAIL_HOST = ‘smtp.gmail.com’                   #邮件smtp服务器 EMAIL_POR ...