意甲冠军:有两个查询:

q=1。在[x,y]间隔,兑换b十进制,数字和m多少个月。

q=2。在[x,y]间隔,兑换b十进制,数字是m第一k的数目是多少(十进制),没有输出由给定的主题。

思维:

和比特的平均数dp如,第几个数的话就是二分推断。

然后就是按常理要开4维,就是dp[i][sum][b][m] i位,和为sum,b进制,最后和为m

可是开不下,所以开3维每次初始化。

注意一下:

1、每次都要初始化

2、x不一定小于y

3、是[x,y]不是(x,y]

代码:

#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"stack"
#include"algorithm"
#include"iostream"
using namespace std;
__int64 dp[33][320][65],num[33]; // i位 和是sum 进制b 的关于m的答案 可是再替m开一维开不下。所以不能在外面初始化
__int64 dfs(__int64 site,__int64 sum,__int64 b,int f,__int64 m)
{
if(site==0) return sum==m?1:0;
if(!f&&dp[site][sum][b]!=-1) return dp[site][sum][b];
__int64 len=f? num[site]:b-1;
__int64 ans=0;
for(__int64 i=0; i<=len; i++)
{
ans+=dfs(site-1,sum+i,b,f&&i==len,m);
}
if(!f) dp[site][sum][b]=ans;
return ans;
}
__int64 solve(__int64 x,__int64 b,__int64 m)
{
int cnt=0;
if(x<0) return 0;
while(x)
{
num[++cnt]=x%b;
x/=b;
}
return dfs(cnt,0,b,1,m);
}
int main()
{
int cas=1;
int q;
while(scanf("%d",&q)!=-1)
{
__int64 x,y,b,m,k;
memset(dp,-1,sizeof(dp)); //必须放里面
printf("Case %d:\n",cas++);
if(q==1)
{
scanf("%I64d%I64d%I64d%I64d",&x,&y,&b,&m);
if(x>y) swap(x,y);
printf("%I64d\n",solve(y,b,m)-solve(x-1,b,m));
}
else
{
scanf("%I64d%I64d%I64d%I64d%I64d",&x,&y,&b,&m,&k);
x--; //注意这里是求 [x,y]区间内的! if(x>y) swap(x,y);
__int64 ans=-1,s;
s=solve(x,b,m);
s+=k;
__int64 l=x+1,r=y;
while(l<=r)
{
__int64 mid=(l+r)/2;
if(solve(mid,b,m)>=s)
{
ans=mid;
r=mid-1;
}
else l=mid+1;
}
if(ans!=-1) printf("%I64d\n",ans);
else puts("Could not find the Number!");
}
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

[数字dp] hdu 3271 SNIBB的更多相关文章

  1. hdu 3271 SNIBB 数位DP+二分

    思路:dp[i][j]:表示第i位在B进制下数字和. 用二分找第k个数! 代码如下: #include<iostream> #include<stdio.h> #include ...

  2. HDU 3271 SNIBB

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

  3. [数字dp] hdu 3565 Bi-peak Number

    意甲冠军: 为了范围[X,Y],的最大位数的范围内的需求高峰和值多少. 双峰是为了满足一些规定数量 你可以切两 /\ /\ 形式. 思维: dp[site][cur][ok]  site地点  面的数 ...

  4. HDU - 4734 F(x) (2013成都网络游戏,数字DP)

    意甲冠军:求0-B见面<=F[A]所有可能的 思维:数字DP,内存搜索 #include <iostream> #include <cstring> #include & ...

  5. fwt优化+树形DP HDU 5909

    //fwt优化+树形DP HDU 5909 //见官方题解 // BestCoder Round #88 http://bestcoder.hdu.edu.cn/ #include <bits/ ...

  6. hdu 3652 B-number(数字dp)

    http://acm.hdu.edu.cn/showproblem.php? pid=3652 大致题意:"B-number"即一个整数含有子串"13"且被13 ...

  7. hdu 3709 数字dp(小思)

    http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...

  8. HDU——B-number(数字DP)

    标题效果: 要了解1至n如何号码之间有许多含有13,并13可分 记忆化搜索: dp[pos][pre][mod][statu],pos位数,pre前一位,mod余数,statu状态 有2个状态:含13 ...

  9. HDU 3271 数位dp+二分

    SNIBB Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. 魔兽争霸war3心得体会(二):狗转蜘蛛,DK光环+游侠二发

    最近几周,勤奋地在QQ对战平台上,练习war3对战. 10年玩到14年初, 也玩了很多,主要是抱着"随便玩玩"的心态,结果也很显然,可以轻松打赢中等电脑,以及AI不够高的发狂的Hu ...

  2. jquery-8 jquery如何处理css样式

    jquery-8  jquery如何处理css样式 一.总结 一句话总结: 1.如何获取网页的三个高? 1)可视区域的高$(window).height(); 2)文档总高度$(document).h ...

  3. windows 空闲超时 非管理员如何破解

    windows 空闲超时 非管理员如何破解

  4. [Angular] NgRx/effect, why to use it?

    See the current implementaion of code, we have a smart component, and inside the smart component we ...

  5. swf loading 自身

    stop(); import flash.net.URLRequest; import caurina.transitions.Tweener; loaderInfo.addEventListener ...

  6. 使用SecureCRT连接AWS的EC2

    如果使用CentOS等linux系统,直接使用ssh命令即可访问AWS上的Linux-EC2实例. $ ssh -i XXX.pem ec2-user@{IP/hostname} 在Windows系统 ...

  7. 子查询及exists

    子查询分为无关子查询和相关子查询 无关子查询,只查询一次,与外查询无关,可作为查询条件: select * from student where sno in (select sno from stu ...

  8. [译]async/await中使用阻塞式代码导致死锁

    原文:[译]async/await中使用阻塞式代码导致死锁 这篇博文主要是讲解在async/await中使用阻塞式代码导致死锁的问题,以及如何避免出现这种死锁.内容主要是从作者Stephen Clea ...

  9. XCode5.1.1怎样实现代码块自己主动排版

    1.问题描写叙述 在开发中常常遇到代码块须要排版的情况,假设一行一行缩进就太out了,但在xcode中怎样实现还真不知道 2.解决方法 2.1选中须要排版的代码块 2.2单击"Editor ...

  10. HSSFWorkBooK用法 ---Excel表的导出和设置

    public ActionResult excelPrint() { HSSFWorkbook workbook = new HSSFWorkbook();// 创建一个Excel文件 HSSFShe ...