LOJ P10163 Amount of Degrees 题解
每日一题 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 题解的更多相关文章
- 【算法•日更•第十二期】信息奥赛一本通1585:【例 1】Amount of Degrees题解
废话不多说,直接上题: 1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB提交数: 130 通过数: 68 [ ...
- Ural1057. Amount of Degrees 题解 数位DP
题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...
- [TimusOJ1057]Amount of Degrees
[TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...
- 一本通1585【例 1】Amount of Degrees
1585: [例 1]Amount of Degrees 时间限制: 1000 ms 内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...
- 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 ...
- [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 ...
- Ural Amount of Degrees(数位dp)
传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...
- [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 ...
- 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 ...
随机推荐
- QT 读写.ini配置文件
当需要存放的数据量较少时合适使用.ini配置文件. #include <QCoreApplication> #include <QSettings> void SystemSe ...
- Sublime实现自动排版
sublime功能很强大, 但是使用sublime就可以实现代码自动重新缩进,使代码缩进重排 方法:Ctrl+A选中全部内容,然后在菜单中选择Edit->Line->Reindent
- PAT(B) 1079 延迟的回文数(Java)
题目链接:1079 延迟的回文数 (20 point(s)) 题目描述 给定一个 k+1 位的正整数 N,写成 ak⋯a1a0 的形式,其中对所有 i 有 0≤ai<10 ...
- 封装函数(累计和、K型、金字塔)
// 假设有个函数,只要传参数进去,就能统计累加的结果 function test($n){ if($n==1){ return 1; } return $n+test($n-1);}echo tes ...
- 路由基础(Routing)
查看本机路由表: [root@controller02 ~]# cat /etc/iproute2/rt_tables # # reserved values # 255 local 254 ...
- VBA错误处理(十八)
在(VBScript/VBA)编程中有三种类型的错误: 语法错误 运行时错误 逻辑错误 语法错误 语法错误(也称为解析错误)发生在VBScript的解释时间. 例如,下面一行导致语法错误,因为它缺少一 ...
- 调试location指令时,直接让location输出文本
有时候我们调试location指令时希望location指令能够直接输出文本,这样能够方便我们进行调试.这时我们可以使用echo模块实现,但是大多数情况我们没有安装这个模块,那么我们还可以使用另一个方 ...
- JSONObject和URL以及HttpURLConnection的使用
1 将java对象类转成json格式 首先引入依赖jar文件 注意依赖文件的版本号,高版本可能没有对应的类 2 我的实体类中包含内部类注意内部类要public才能被序列化成json格式 import ...
- UI5-技术篇-jQuery.ajax执行过程中Token验证及JSON格式传值问题
最近两天在测试OData服务类方法CREATE_DEEP_ENTITY及GET_EXPANDED_ENTITYSET,刚开始采用ODataModel方式调用没有任何问题,但是ODataModel采用的 ...
- java引用传递和值传递
关于Java传参时是引用传递还是值传递,一直是一个讨论比较多的话题,有论坛说Java中只有值传递,也有些地方说引用传递和值传递都存在,比较容易让人迷惑.关于值传递和引用传递其实需要分情况看待,今天学习 ...