思路: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. 常见的百度蜘蛛IP

    根据不同的IP我们可以分析网站是个怎样的状态, 以下常见的百度蜘蛛IP: 123.125.68.*这个蜘蛛经常来,别的来的少,表示网站可能要进入沙盒了,或被者降权. 220.181.68.*每天这个I ...

  2. 【Valid Number】cpp

    题目: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " = ...

  3. 重读《Struts In Action》

    Figure   1.1. The Java Servlet API exposes the HTTP client/server protocol to the Java   platform. S ...

  4. Jenkins-测试自动化环境搭建(Python+RobotFramework+selenium)

    下载插件: Python:https://wiki.jenkins-ci.org/display/JENKINS/Python+Plugin RobotFramework:https://wiki.j ...

  5. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  6. Codeforces Round #281 (Div. 2)

    题目链接:http://codeforces.com/contest/493 A. Vasya and Football Vasya has started watching football gam ...

  7. spring AspectJ的Execution表达式说明

    Aspectj切入点语法定义 在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点" 例如定义切入点表达式 execut ...

  8. openOffice将doc在线预览

    最近,有个项目要用到类似DOCIN的文档转换和阅读的功能,于是就开始找相关的资料,最后总结出2种解决办法,以下就来探讨下两种方法的各自实现. 第一种:通过FLASH PAPER来转换DOC文档直接生成 ...

  9. SQL SERVER 导出到Oracle 问题与技巧

    工具: 使用SQL SERVER自带的导入, 导出工具   技巧: 一. 使用Oracle Provider for OLE DB(强制推荐) 1. 速度快 2. 要安装Oracle驱动(Oracle ...

  10. 阿里云centos配置ftp和svn全过程

    1.下载xshell 2.登录centos 3.安装vsftpd [root@xxx]# yum install vsftpd //安装vsftpd [root@xxx]# chkconfig vsf ...