数位DP模板
来源:互联网 发布:端口能ping吗 编辑:程序博客网 时间:2024/06/09 13:53
不管什么鬼,直接long long 上
#include <cstdio>#include <cstring>#include <iostream>using namespace std;#define ll long longconst int maxn=20;int bit[maxn];ll dp[maxn][2][2][13]; //dp[i][j][k][k]:长度为i,是否以1结尾,有无13,模13的结果//[a,b]中含13且取模13为0的数个数ll dfs(int len,bool end1,bool have13,int mod,bool ismax){ if(len==0) return (!mod && have13); if(!ismax && (dp[len][end1][have13][mod] != -1)) return dp[len][end1][have13][mod]; int pmax = ismax ? bit[len] : 9; ll cnt = 0; for (int i = 0; i <= pmax; ++i){ int tmod = (mod*10+i) % 13; cnt += dfs(len-1,i==1,have13||(end1&&i==3),tmod,ismax && i == pmax); } return ismax ? cnt : dp[len][end1][have13][mod] = cnt;}ll solve(ll n){ int cnt=0; while(n>0){ bit[++cnt]=n%10; n/=10; } return dfs(cnt,false,false,0,true);}int main(){ ll a,b; memset(dp,-1,sizeof(dp)); while(cin>>a>>b){ cout<<solve(b)-solve(a-1)<<endl; } return 0;}
相关题目链接
0 0
- 数位dp模板
- 数位DP模板
- 数位DP模板
- 数位DP模板
- 【自用模板】数位dp
- 数位DP模板
- 数位DP模板
- 数位DP模板详解
- 数位DP模板
- 数位DP模板
- 数位DP模板
- 数位DP模板
- 数位DP(模板)
- 数位DP模板
- 数位DP模板
- 数位DP模板
- 【数位DP模板】
- 数位dp模板
- GridView的一些特殊属性
- vim 配置
- J2EE 总结
- Oracle初探(一)
- Windows10中的IIS10安装php manager和IIS URL Rewrite 2.0组件的方法
- 数位DP模板
- LInux内核同步与互斥
- Linux进程调度机制(1)
- Spring 使用注解方式进行事务管理
- Exerciese——PrintMatrixClockwise
- jquery的ajax 处理后台传来json格式的二维数组
- Log日志打印集合类型
- 关于Posix共享内存
- javascript 中的location.pathname