HDU 4389——X mod f(x)(数位DP)
来源:互联网 发布:java语言入门电子书 编辑:程序博客网 时间:2024/06/04 19:54
X mod f(x)
Problem Description
Here is a function f(x):
int f ( int x ) {
if ( x == 0 ) return 0;
return f ( x / 10 ) + x % 10;
}
Now, you want to know, in a given interval [A, B] (1 <= A <= B <= 109), how many integer x that mod f(x) equal to 0.
Input
The first line has an integer T (1 <= T <= 50), indicate the number of test cases.
Each test case has two integers A, B.
Output
For each test case, output only one line containing the case number and an integer indicated the number of x.
Sample Input
21 10
11 20
Sample Output
Case 1: 10
Case 2: 3
————————————————————————分割线—————————————————————
记忆化搜索:
数据范围是10的9次方,数位和最大为9*9=81,枚举数位和
每次要维护:pos维数,当前数位和a,枚举的数位和b,当前的模mo,有无上限e
dp [pos] [a] [b] [mo];
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<vector>#include<queue>#include<deque>#include<stack>#include<map>#include<set>#include<cmath>#include<cstdlib>#include<cctype>#define inf 0x3f3f3f3f#define maxn 10000typedef long long LL;using namespace std;int dp[11][82][82][82];int num[11],pos,n,m;int dfs(int pos,int a,int b,int mo,int e){ if(pos==-1) return a==b&&!mo; if(!e&&dp[pos][a][b][mo]!=-1) return dp[pos][a][b][mo]; int end=e?num[pos]:9; int sum=0; for(int i=0;i<=end;i++){ sum+=dfs(pos-1,a+i,b,(mo*10+i)%b,e&&i==end); } return e?sum:dp[pos][a][b][mo]=sum;}void Init(int x){ pos=0; while(x){ num[pos++]=x%10; x/=10; }}int cal(int x){ Init(x); int res=0; for(int i=1;i<=81;i++){ res+=dfs(pos-1,0,i,0,1); } return res;}int main(){ int t,iCase=1; memset(dp,-1,sizeof dp); cin>>t; while(t--){ scanf("%d%d",&m,&n); printf("Case %d: %d\n",iCase++,cal(n)-cal(m-1)); }return 0;}
- HDU 4389 x mod f(x)数位DP
- hdu 4389 X mod f(x) (数位DP)
- HDU 4389 X mod f(x) (数位dp)
- HDU 4389——X mod f(x)(数位DP)
- HDU 4389 X mod f(x) 数位统计DP
- HDU 4389 X mod f(x)[数位统计dp]
- HDU 4389 X mod f(x) 数位DP
- hdu 4389 X mod f(x)(数位dp)
- HDU 4389 X mod f(x) (数位DP)
- HDU 4389 X mod f(x) 平方分割 数位DP
- [数位dp] hdu 4389 X mod f(x)
- hdu 4389 X mod f(x) 数位dp
- HDU 4389 X mod f(x) (数位DP)
- hdu 4389 X mod f(x) 数位dp
- hdu 4389 X mod f(x) (数位dp||打表)
- 【数位DP】HDU 4389 X mod f(x)
- HDU 4389X mod f(x) 数位dp
- hdu 4389 X mod f(x) 数位dp
- php在Windows下获取文件夹和大文件大小
- 在win8下安装tomcat8.0后,点击bin 目录下的启动文件startup.bat后,控制台一闪而过,根本启动不了tomcat
- hibernate联合主键hbm.xml配置
- About Software Security(关于软件安全)
- 项目是很容易的
- HDU 4389——X mod f(x)(数位DP)
- OBJ文件格式内幕详解
- Service与Android系统设计(2)-- Parcel
- VS 学习笔记-C++相关
- java+jquery form实现异步上传文件,并且成功返回
- Leetcode :Sort List
- 常见非关系型数据库(NoSQL)推荐介绍
- 【广告时间】这么便宜的网络电话卡,你家里人都知道吗?
- 在C++中模拟Java中final对虚函数的使用