思路:

每次枚举数字和也就是取模的f(x),这样方便计算。

其他就是基本的数位Dp了。

代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define MAX 50000
using namespace std;
int bit[],dp[][][][];
int dfs(int pos,int num,int mod,int sum,bool f)
{
if(pos==-) return mod==sum&&num==;
if(!f&&dp[pos][mod][num][sum]!=-) return dp[pos][mod][num][sum];
int ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
ans+=dfs(pos-,(*num+i)%mod,mod,sum+i,f&&i==bit[pos]);
}
if(!f) dp[pos][mod][num][sum]=ans;
return ans;
}
int cal(int n)
{
int m=;
while(n){
bit[m++]=n%;
n/=;
}
int ans=;
for(int i=;i<=*m;i++)
ans+=dfs(m-,,i,,);
return ans;
}
int main(){
int t,n,m,ca=;
memset(dp,-,sizeof(dp));
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
printf("Case %d: %d\n",++ca,cal(m)-cal(n-));
}
return ;
}

hdu 4389 X mod f(x) 数位DP的更多相关文章

  1. HDU - 4389 X mod f(x)(数位dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 为[A,B] 区间内的数能刚好被其位数和整除的数有多少个. 分析 典型的数位dp...比赛时想不出状 ...

  2. HDU 4389——X mod f(x)(数位DP)

    X mod f(x) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  3. HDU 4389 X mod f(x)

    题意:求[A,B]内有多少个数,满足x % f(x) == 0. 解法:数位DP.转化为ans = solve(b) - solve(a - 1).设dp[i][sum][mod][r]表示长度为i, ...

  4. HDU4389:X mod f(x)(数位DP)

    Problem Description Here is a function f(x): int f ( int x ) { if ( x == 0 ) return 0; return f ( x ...

  5. HDU 4734 F(x) ★(数位DP)

    题意 一个整数 (AnAn-1An-2 ... A2A1), 定义 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,求[0..B]内有多少 ...

  6. HDOJ 4389 X mod f(x)

    数位DP........ X mod f(x) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  7. 【HDU 3709】 Balanced Number (数位DP)

    Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced ...

  8. HDU 5642 King's Order【数位dp】

    题目链接: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=677&pid=1003 题意: 求长度为n的序列 ...

  9. HDU - 4352 - XHXJ's LIS(数位DP)

    链接: https://vjudge.net/problem/HDU-4352 题意: a 到 b中一个数组成递增子序列长度等于k的数的个数 思路: 因为只有10个数,使用二进制维护一个递增序列,每次 ...

随机推荐

  1. AppCan移动技术全景图:创新、协作、支撑

    开发者是移动互联网宏伟蓝图的最终实现者.如果你有创意.有技术,你可以开发一款服务上亿人的应用.所以,我感觉幸运,没有任何一个时代,能像现在这么好,技术人能够服务这么广大的市场,能够撬动百亿级的市场. ...

  2. hdu 2425 Hiking Trip

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...

  3. ios中怎么样设置drawRect方法中绘图的位置

    其中drawRect方法中的参数rect就是用来设置位置的,

  4. Client–server model

    Client–server model From Wikipedia, the free encyclopedia The client–server model of computing ] Oft ...

  5. win7 系统如何设置快速启动栏

    a.在任务栏上右键 -> 工具栏 -> 新建工具栏 -> 跳出选择文件夹对话框,在文件夹里面(光标山洞处)输入这个路径,然后按回车: %userprofile%\AppData\Ro ...

  6. Abstract Class与 Interface 的区别

    表格                                                                                               Abs ...

  7. Session invalidate

    会清空所有已定义的session 而不是清空全部session的值也就是说 定义了一个名为 user 的session 调用invalidate()方法后使用Session.getValue(“use ...

  8. c语言学习strcopy

    自己写了一个字符串复制函数: #include<stdio.h> #include<assert.h> char *mystrcpy(char *des,char *ser) ...

  9. 【Roman To Integer】cpp

    题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...

  10. 【转载】Android异步处理系列文章

    本博文地址:http://blog.csdn.net/mylzc/article/details/6777767 转载请注明出处. 为了给用户带来良好的交互体验,在Android应用的开发过程中需要把 ...