nowcoder A hard problem /// 数位DP
题目大意:
称一个数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 ;
}
nowcoder A hard problem /// 数位DP的更多相关文章
- hdu 5106 Bits Problem(数位dp)
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...
- hiho1259 A Math Problem (数位dp)
题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 ...
- 哈尔滨工程大学ACM预热赛 G题 A hard problem(数位dp)
链接:https://ac.nowcoder.com/acm/contest/554/G Now we have a function f(x): int f ( int x ) { if ( ...
- 『The Counting Problem 数位dp』
The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结 ...
- UVA - 1640 The Counting Problem (数位dp)
题意:统计l-r中每种数字出现的次数 很明显的数位dp问题,虽然有更简洁的做法但某人已经习惯了数位dp的风格所以还是选择扬长避短吧(说白了就是菜啊) 从高位向低位走,设状态$(u,lim,ze)$表示 ...
- POJ2282:The Counting Problem(数位DP)
Description Given two integers a and b, we write the numbers between a and b, inclusive, in a list. ...
- Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- 2018.09.28 hdu5435A serious math problem(数位dp)
传送门 数位dp卡常题. 写了一发dfs版本的发现过不了233. 于是赶紧转循环版本. 预处理出f数组. f[i][j]f[i][j]f[i][j]表示前i位数异或和为j的方案数. 然后每次直接数位d ...
- 2019长安大学ACM校赛网络同步赛 L XOR (规律,数位DP)
链接:https://ac.nowcoder.com/acm/contest/897/L 来源:牛客网 XOR 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
随机推荐
- [转载]Redux原理(一):Store实现分析
写在前面 写React也有段时间了,一直也是用Redux管理数据流,最近正好有时间分析下源码,一方面希望对Redux有一些理论上的认识:另一方面也学习下框架编程的思维方式. Redux如何管理stat ...
- Python人工智能识别文字内容(OCR)
环境准备 安装pytesseract和PIL 安装这两个包可以借助pip命令行安装 pip install PIL pip install pytesseract 安装识别引擎tesseract-oc ...
- DFSORT
1.1 Outline I. Introduction Overview 2.1 What is DFSORT? 2.2 Usage of DFSORT 2 ...
- spring 整合rabbitMQ
<!-- 配置邮件消息队列监听 --> <bean id="maillistener" class="cn.xdf.wlyy.listener.Mail ...
- websock(AMQ)通信-前端
服务端和客户端之间的通信 前端开发经常会依赖后端,那么如果后端服务器还没做好推送服务器,那么前端该如何呢.最简单的就是自己模拟一个服务器,用node来搭建,这边只简单介绍搭建的过程 node搭建服务器 ...
- hive中Sort By,Order By,Cluster By,Distribute By,Group By的区别
order by: hive中的order by 和传统sql中的order by 一样,对数据做全局排序,加上排序,会新启动一个job进行排序,会把所有数据放到同一个reduce中进行处理,不管数 ...
- html中 的method=post和method=get的区别
1. get是从服务器上获取数据,post是向服务器传送数据. 2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过 ...
- iis7反向代理
很多站长通常在Linux系统下使用nginx作为前端server,通过反向代理间接访问其他webserver.那么如果用户安装的是Windows系统的话,又改如何实现反向代理的设置呢?搜索引擎大全 下 ...
- python3安装pdfminer并使用
1.python3不同与2版本不能使用pdfminer pip install pdfminer3k 2.使用pdfminer解析相应文档并保存到相应的文件夹中 # encoding : udf-8 ...
- v-show与v-if的区别
v-show有dom节点像display:none,而v-if隐藏的则没有dom节点.两个共同点都可以显隐