思路: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. struts2传递参数值的3中方式

    在使用struts2的时候,当要传递的参数不多的时候,我们会选择使用属性来传参,而当要传递的参数很多的时候,或者多个action会有共用的参数时,我们会使用另外两种传参方式. 注意:使用Model D ...

  2. WIndows7 多版本

    Windows7 安装U盘 删除source\ei.cfg 以后开机安装会提示安装的版本

  3. zeromq

    分布式系统之分布式中间件zeroMQ zeroMQ,又称0MQ,是一个非常简单的通信库,它扩展了传统BSD socket能力,提供简单的基于消息的通信.zeroMQ不解析消息体,没有序列化能力,或者说 ...

  4. C# socket 实现消息中心向消息平台 转发消息

    公司用到,直接粘代码了 using System; using System.Collections.Generic; using System.Configuration; using System ...

  5. GoAhead 嵌入式web

    https://embedthis.com/goahead/ 入手了一个360  4g  wifi :使用jquery  .goahead Goahead webserver编辑 GoAhead We ...

  6. OC开发中运用到的枚举

      一  常见枚举的定义: typedef enum { LOGIN_SUCCESS, USER_NAME, USER_PASSWORD, OLD_LAT, OLD_LNG }FIELD_SAVED; ...

  7. 微软职位内部推荐-Software Engineer II-SDP

    微软近期Open的职位: Position: SDE II The R&D of Shared Data Platform at Application and Services Group ...

  8. 转载 SQL Server 2008 R2 事务与隔离级别实例讲解

    原文:http://blog.itpub.net/13651903/viewspace-1082730/ 一.事务简介 SQL Server的6个隔离级别中有5个是用于隔离事务的,它们因而被称作事务隔 ...

  9. 【收藏】win7打开word每次提示配置解决办法

    打开“我的电脑”——“ C:\Program Files\Common Files\Microsoft Shared\OFFICE12\Office Setup Controller ”——找到一个“ ...

  10. iptables的recent模块

    看到文章中用recent模块控制对主机的访问. 配置方法如下: iptables -A INPUT -p icmp --icmp-type 8 -m length --length 78 -j LOG ...