每日一题 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. 第四章 函数之lambda 表达式和内置函数

    4.5 lambda 表达式 用于表示简单的函数. # 三元运算,为了解决简单的if else的情况,如:if 1 == 1:    a = 123else:    a = 456# 相当于a = 1 ...

  2. Python字符串图解

    >>> word = "Python" >>> word[:2]  # character from the beginning to posi ...

  3. java实现HTTP请求 HttpUtil

    示例: package com.sensor.utils; import java.net.HttpURLConnection; import java.net.URL; public class H ...

  4. windows下安装phpredis扩展

    根据phpyinfo获取自己的php信息 x86,php5.6,TS,VC11 在pecl网站上找到对应的版本 5.6 Thread Safe (TS) x86 https://pecl.php.ne ...

  5. CVPR2014: DeepID解读

    上周五就要发的,拖........拖.......拖到现在,文中有不准确的地方,欢迎批评指正. DeepID是一种特征提取的算法,由港中文汤晓鸥团队于2014年提出,发表于CVPR2014.其应用领域 ...

  6. js钩子函数实现一个简单动画

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...

  7. Source Insight用法

    快捷键 Symbol: Browse Project Symbols-:F7, Alt+G Relation View Relationship->For Functions->Pefer ...

  8. LCD驱动的学习

    简介: LCD是基于液晶的. LCD(liquid crystal display)按驱动方式分类可以分为静态驱动,简单矩阵驱动,主动矩阵驱动.其中,简单矩阵又可以分为扭转向列型(TN)和超转向列型( ...

  9. LeetCode:137. 只出现一次的数字 II

    LeetCode:137. 只出现一次的数字 II 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. ...

  10. 【新品发布】智能驾驶实车测试系统-VDAS

    智能驾驶技术的迭代研发,需要多种传感器.海量数据.海量场景的支撑.而目前多种传感器Gbit/s级别的数据同步采集.海量数据的快速分析和评估.关键场景的切片和提取,是业界公认的棘手问题. 为了解决上述的 ...