题目大意:

称一个数x的各个数位之和为f(x)

求区间L R之间 有多少个数x%f(x)==0

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define inc(i,j,k) for(int i=j;i<=k;i++)
#define dec(i,j,k) for(int i=j;i>=k;i--)
#define gcd(i,j) __gcd(i,j)
#define mem(i,j) memset(i,j,sizeof(i))
const int N=2e5+; int rd, dfn[][][][];
int fx, tot, a[];
LL dp[][][][];
// dp[f][w][s][m]
// f为1说明不是上界 此时为第w位数
// 剩下的数位总和为s 此时的数位总和%f(x)为m LL DFS(int f,int w,int s,int m) {
if(w==) return (s==&&m==);
// 所有位都枚举过了则w=0
// 所有数位总和为fx则s=0
// x%fx==0则m=0
if(dfn[f][w][s][m]==rd) return dp[f][w][s][m];
dfn[f][w][s][m]=rd;
LL res=0LL;
int l=max(,s-*(w-)), r=min((f ? :a[w]),s);
for(int i=l;i<=r;i++) // 枚举当前位的数
res+=DFS(f|(i<a[w]),w-,s-i,(m*+i)%fx);
// 之前不是上界 或 当前位不是上界 则到目前为止都不达上界
// 位数-1 剩余数位总和需减去当前位的数 更新余数
return dp[f][w][s][m]=res;
} LL solve(int x) {
mem(dp,); mem(dfn,);
int tot=;
while(x) { a[++tot]=x%; x/=; }
int all=tot*;
LL res=0LL;
for(fx=;fx<=all;fx++) // 枚举所有数位总和
++rd, res+=DFS(,tot,fx,);
//printf("%lld\n",res);
return res;
} int main()
{
int _; scanf("%d",&_);
inc(i,,_) {
int l,r; scanf("%d%d",&l,&r); rd=;
printf("Case %d: ",i);
printf("%lld\n",solve(r)-solve(l-));
} return ;
}

最新文章

  1. iOS为真机调试增加scribble来定位野指针
  2. javascript里面foreach遍历函数介绍,以及跟jquery里面each的区别
  3. Ajax全解
  4. Silverlight动画学习笔记(三):缓动函数
  5. Matlab与科学计算的基本运算
  6. POJ1159 Palindrome(dp)
  7. Applovin Interview (面经)
  8. Linux 常 用 命 令
  9. Cannot create an instance of OLE DB provider “OraOLEDB.Oracle” for linked server &quot;xxxxxxx&quot;.
  10. js实现两种实用的排序算法——冒泡、快速排序
  11. Linux input子系统 io控制字段【转】
  12. ucloud mysql
  13. 超实用的JavaScript代码段 Item5 --图片滑动效果实现
  14. 02:安装 Kerberos
  15. MapReduce实现PageRank算法(稀疏图法)
  16. Xamarin Android ListView 控件使用
  17. curl模拟访问已经存在的cookie
  18. vue 环境报错 chromedriver@2.44.1 install: `node install.js`
  19. P3379 【模板】最近公共祖先(LCA)(树链剖分)版
  20. SGU刷题之路开启

热门文章

  1. 攻防世界--re2-cpp-is-awesome
  2. 获取class的儿子,报错undefined
  3. tomcat常用功能
  4. 牛客多校第10场J Wood Processing 分治优化/斜率优化 DP
  5. java使用对象类型作为方法的参数
  6. Java8 stream基础
  7. ruby语法之方法
  8. 【leetcode】44. Wildcard Matching
  9. cocos2D-X 打包
  10. 初识java-1.Java跨平台的原理