每日一题 day6 打卡

Analysis

题目的意思是找在区间[x,y]之间满足能够由k个b的不同次幂相加得到的数的总数。这题的关键是转换进制,之前几道题我们保存的是数的每位数,其实也就是10进制,这题我们要保存的是b进制,所以在ask函数中要把原来的对10求余和除10都要改成对b进行操作,dp[x][pre]数组表示第x位由pre个b的不同次幂相加得到的数的总数。在判断进入递归的if条件语句中,i的上界要同时满足小于上界且小于等于1,因为根据题意,只有类似3^4次方能够算进去,2*3^4并不能计入,也就是说系数必须小于等于0,且只有等于1时,sta才能增1。还有最后一个要注意的是当x=0递归结束时,只有当pre=k时,才是符合条件的数,ans才能增加。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define fa_q 5010
using namespace std;
typedef long long ll;
inline ll read()
{
ll x=;
bool f=;
char c=getchar();
for(; !isdigit(c); c=getchar()) if(c=='-') f=;
for(; isdigit(c); c=getchar()) x=(x<<)+(x<<)+c-'';
if(f) return x;
return -x;
}
inline void write(ll x)
{
if(x<){putchar('-');x=-x;}
if(x>)write(x/);
putchar(x%+'');
}
ll dp[fa_q][fa_q],dim[fa_q];
ll x,y,k,b;
ll dfs(int x,int pre,int bj)
{
if(x==) return pre==k;
if(!bj&&dp[x][pre]!=-) return dp[x][pre];
int maxn=bj?dim[x]:b-;
ll temp=;
for(int i=;i<=min(maxn,);i++)
{
temp+=dfs(x-,pre+(i==),bj&&i==maxn);
}
if(!bj) dp[x][pre]=temp;
return temp;
}
ll ask(ll x)
{
dim[]=;
while(x)
{
dim[++dim[]]=x%b;
x/=b;
}
return dfs(dim[],,);
}
int main()
{
memset(dp,-,sizeof(dp));
x=read();y=read();k=read();b=read();
write(ask(y)-ask(x-));
return ;
}

请各位大佬斧正(反正我不认识斧正是什么意思)

LOJ P10163 Amount of Degrees 题解的更多相关文章

  1. 【算法•日更•第十二期】信息奥赛一本通1585:【例 1】Amount of Degrees题解

    废话不多说,直接上题: 1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB提交数: 130     通过数: 68 [ ...

  2. Ural1057. Amount of Degrees 题解 数位DP

    题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...

  3. [TimusOJ1057]Amount of Degrees

    [TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...

  4. 一本通1585【例 1】Amount of Degrees

    1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...

  5. Timus Online Judge 1057. Amount of Degrees(数位dp)

    1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...

  6. [ACM] ural 1057 Amount of degrees (数位统计)

    1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...

  7. Ural Amount of Degrees(数位dp)

    传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...

  8. [ural1057][Amount of Degrees] (数位dp+进制模型)

    Discription Create a code to determine the amount of integers, lying in the set [X; Y] and being a s ...

  9. URAL 1057 Amount of Degrees (数位dp)

    Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactly ...

随机推荐

  1. Linux基础-04-权限

    1. 查看文件的权限 1) 使用ls –l命令查看文件上所设定的权限. -rw-r--r-- 1 root root 605 Mar 18 20:28 .jp1.tar.gz 权限信息 属主 属组 文 ...

  2. 理解atoi()函数

    atoi函数 功能:字符串转化为整型数 #include <iostream> using namespace std; int atoi_my(const char *str) { ; ...

  3. FFmpeg开发教程一、FFmpeg 版 Hello world

    本系列根据项目ffmpeg-libav-tutorial翻译而来 Chapter 0 - 万物之源 -- hello world 然而,本节的程序并不会在终端打印"Hello world&q ...

  4. PB数据窗口分页

    第一步:增加一个计算列,此计算列必须放在Detail段,Expression中输入: ceiling(getrow()/500)  --这里500还可以用全局函数取代,这样可以允许用户任意设置每页多少 ...

  5. 在论坛中出现的比较难的sql问题:16(取一个字段中的数字)

    原文:在论坛中出现的比较难的sql问题:16(取一个字段中的数字) 所以,觉得有必要记录下来,这样以后再次碰到这类问题,也能从中获取解答的思路. 问题:取一个字段中的数字http://bbs.csdn ...

  6. VS2015功能介绍

    1.New Web Site新网站 Recent 系统文件夹,里面存放最近使用的文档的快捷方式,以便再次访问(可删除) Installed 安装 Templates 样板,模板 Online 联网 . ...

  7. 使用angularJS设置复选框的回显状态

    思路分析: 在angularJS中,我们可以使用ng-checked="expression()"来设置复选框的状态:当expression()返回true时,该复选框为选择中状态 ...

  8. C++实现企业链表(单向链表的另外一种实现方式)

    LinkList.h #include <windows.h> #include <stdio.h> // 链表小结点 typedef struct LINKNODE { LI ...

  9. orangepi设置vnc开机自启动

    首先需要创建一个文件,执行以下命令,自动打开空白文件,在里面编辑内容即可 sudo gedit /etc/init.d/tightvncserver 把以下内容粘贴进去,然后点击保存即可. #!/bi ...

  10. SDL -安全开发生命周期

    1.学习SDL https://www.cnblogs.com/whoami101/p/9914862.html 2.学习SDL https://blog.csdn.net/whatday/artic ...