思路:dp[i][j]:表示第i位在B进制下数字和。

用二分找第k个数!

代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
using namespace std;
int dp[][],b,m,bit[];
int dfs(int pos,int mm,bool f)
{
if(pos==-) return mm==m;
if(!f&&dp[pos][mm]!=-) return dp[pos][mm];
int ans=;
int e=f?bit[pos]:(b-);
for(int i=;i<=e;i++){
ans+=dfs(pos-,mm+i,f&&i==bit[pos]);
}
if(!f) dp[pos][mm]=ans;
return ans;
}
int solve(int n)
{
if(n<=) return n==m;
int s=;
while(n){
bit[s++]=n%b;
n/=b;
}
return dfs(s-,,);
}
int main(){
int q,x,y,n,k,ca=;
while(scanf("%d%d%d%d%d",&q,&x,&y,&b,&m)!=EOF){
memset(dp,-,sizeof(dp));
printf("Case %d:\n",++ca);
if(x>y) swap(x,y);
if(q==) printf("%d\n",solve(y)-solve(x-));
else{
scanf("%d",&k);
int low=solve(x-);
int high=solve(y);
if(high-low<k){
puts("Could not find the Number!");
continue;
}
int l=x,r=y,mid,ans=;
while(l<=r){
mid=(int)(((ll)l+(ll)r)>>);
int t=solve(mid);
if(t-low>=k) r=mid-,ans=mid;
else l=mid+;
}
printf("%d\n",ans);
}
}
return ;
}

hdu 3271 SNIBB 数位DP+二分的更多相关文章

  1. HDU 3271 SNIBB

    SNIBB Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 3271 ...

  2. poj3208 Apocalypse Someday 数位dp+二分 求第K(K <= 5*107)个有连续3个6的数。

    /** 题目:poj3208 Apocalypse Someday 链接:http://poj.org/problem?id=3208 题意:求第K(K <= 5*107)个有连续3个6的数. ...

  3. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  4. HDU 2089 简单数位dp

    1.HDU 2089  不要62    简单数位dp 2.总结:看了题解才敲出来的,还是好弱.. #include<iostream> #include<cstring> #i ...

  5. HDU(3555),数位DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...

  6. HDU(4734),数位DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4734 F(x) Time Limit: 1000/500 MS (Java/Others) ...

  7. HDU 3555 Bomb 数位dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...

  8. hihocoder #1301 : 筑地市场 数位dp+二分

    题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostr ...

  9. Hdu 4734 【数位DP】.cpp

    题意: 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~ ...

随机推荐

  1. iOS代码实践总结

    转载地址:http://mobile.51cto.com/hot-492236.htm 最近一个月除了专门抽时间和精力重构之外,还有就是遇到需要添加功能的模块的时候,由于项目中的代码历史因素比较多,第 ...

  2. Couchbase server---Enyim.Caching.dll

    本文不打算抄袭官方或者引用他人对Couchbase的各种描述,仅仅是自己对它的一点理解(错误之处,敬请指出),并附上一个入门示例. ASP.NET Web项目(其他web开发平台也一样)应用规模小的时 ...

  3. DXP中原理图与PCB图元件互找

    在原理图中找到元件,快捷键TS即可在PCB中找到元件,且为选中状态.

  4. java静态变量、静态方法和静态代码段

    先上实例 public class TestStatic { public static String staticString = "this is a static String&quo ...

  5. 文件操作的openmode

    C中文件的openmode如下: r 只读 为输入打开一个文本文件 w 只写 为输出打开一个文本文件 a 追加 向文本文件尾添加数据 rb 只读 为输入打开一个二进制文件 wb 只写 为输出打开一个二 ...

  6. IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)

    ... 首先了解一下CGContextRef: An opaque type that represents a Quartz 2D drawing environment. Graphics Con ...

  7. IBM MQ消息中间件jms消息中RHF2消息头的处理

    公司的技术平台在和某券商对接IBM MQ消息中间件时,发送到MQ中的消息多出了消息头信息:RHF2,造成消息的接收处理不正常.在此记录此问题的处理方式. 在IBM MQ中提供了一个参数 targetC ...

  8. shell ulimit -n

    通过ulimit -n命令可以查看linux系统里打开文件描述符的最大值,一般缺省值是1024,

  9. 【转】EXT VTYPE自定义举例

    原文地址:http://www.blogjava.net/xiaohuzi2008/archive/2012/12/08/392676.html 近日来对Ext特别感兴趣,也许是它那种OO的设计思想吸 ...

  10. 【CentOS】搭建git服务器

    参考资料: https://github.com/jackliu2013/recipes/blob/master/doc/linux/CentOS_6.4_git服务器搭建.md http://blo ...