思路:

每次枚举数字和也就是取模的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. hdu 4857 逃生

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4857 逃生 Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能 ...

  2. Tutorial: Analyzing sales data from Excel and an OData feed

    With Power BI Desktop, you can connect to all sorts of different data sources, then combine and shap ...

  3. 为什么学习Python

    因为做iOS开发的,之前一直用OC,但是突然有一天苹果说出Swift,但是那时候的Swift真的是Bug多多,语法都不固定,所以只是大致看了看,而一年多之后,Swift已经发布2.0了,语言也相对稳定 ...

  4. java程序用做windows服务

    具体步骤在这里 http://www.doc88.com/p-360144091164.html 遇到错误: JVM did not exit on request, terminated 通过下面的 ...

  5. Entity Framework 学习第二天 续

    今天来写一点不一样的删除,修改,查询 下面只写了几个方法 /// <summary> /// 根据删除条件进行删除 /// </summary> /// <param n ...

  6. Qt的Qss样式

    http://www.cnblogs.com/coffeegg/archive/2011/11/15/2249452.html(转) http://blog.csdn.net/cgzhello1/ar ...

  7. UIToolbar swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  8. Unity3d之Animation(动画系统)

    1,动画系统配置,2,代码控制动画 原文地址: http://blog.csdn.net/dingkun520wy/article/details/51247487 1,动画系统配置 创建游戏对象并添 ...

  9. 微软职位内部推荐-Senior Software Engineer-News

    微软近期Open的职位: News is a critical areas for integration of mobile and services, one of the top priorit ...

  10. c++函数内部声明函数,在函数外面实现函数是可以的

    这个具体有什么用我也不大清楚,只知道可以这样 #include <iostream> //#include "header1.h" using namespace st ...