思路: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. ORACLE SQL TUNING ADVISOR 使用方法

    sql tunning advisor 使用的主要步骤: 1 建立tunning task 2 执行task 3 显示tunning 结果 4 根据建议来运行相应的调优方法  下面来按照这个顺序来实施 ...

  2. 别跟我来这套 Hot Swap 热插拔

    如果你觉得我们演的不好,可以随时打断,如果你觉得怎么演好可以随时来改,你都可以直接来演.

  3. squid判断文件是否修改机制分析

    前提: 1.我写了一个简单的http服务器,以下简称 httpserver 2.前端使用squid做反向代理,以下简称 squid.squid同时反向代理了2台http服务器,其中一台是httpser ...

  4. ifstat-网络接口监测工具

    ifstat-网络接口监测工具 http://gael.roualland.free.fr/ifstat/ ifstat is a tool to report network interfaces ...

  5. sharepoint 2010 切换域

    前提: 现在已经有一个sharepoint 2010的环境,当前域为contosoA.com,有个需求需要将这个域切换到域contosoB.com.下面是成功操作的步骤. 1.数据最重要 备份所有数据 ...

  6. sharepoint 浏览页面导航不正确

    问题是这样的: sharepoint网站上建立一个二级站点,然后在网站中创建几个页面.当浏览二级网站的页面的时候,顶部导航的位置总是在首页的地方,而不是我的二级站点的导航位置. 解决方法: 转到网站集 ...

  7. Matlab 支持向量机(SVM)实现多分类

    1.首先,你需要安装完成Matlab. 2.将libsvm-3.17.zip和drtoolbox.tar文件解压到:libsvm-3.17文件夹和drtoolbox,并放到MATLAB的工具箱安装目录 ...

  8. c enum用法

    c语言中enum的用法,先用关键字enum声明一个类型如enum HUMAN {MAN ,WOMAN};这里就声明了一个HUMAN这个枚举类型.其中MAN的值为0,后面依次递增.后面要用的时候,先声明 ...

  9. c++函数内部声明函数,在函数外面实现函数是可以的

    这个具体有什么用我也不大清楚,只知道可以这样 #include <iostream> //#include "header1.h" using namespace st ...

  10. nginx简单反向代理和负载均衡(ubuntu)

    nginx简单反向代理与负载均衡 环境:三台ubuntu 12.04.5 虚拟机    均装有nginx 1.1.19 以下u1(192.168.240.129) ,u2(192.168.240.13 ...