codeforces 55D
来源:互联网 发布:sql server 2005安装 编辑:程序博客网 时间:2024/05/20 07:37
题目链接:http://codeforces.com/problemset/problem/55/D
注意内存
2520是2~9的最大公约数,
#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;typedef __int64 ll;int num[20];ll dp[20][2520][256];//256的二进制表示2~9的有无bool check(int tra, int mod){ for(int i = 0; i < 8; i++) { if(mod&(1<<i)) { if(tra%(i+2) != 0) return false; } } return true;}ll dfs(int len,int tra,int mod,int fp)//tra是len位之前取模2520的结果{ if(!len) { if(!tra || check(tra,mod)) return 1; return 0; } if(!fp && dp[len][tra][mod]!=-1) return dp[len][tra][mod]; int fpmax = fp ? num[len] : 9; int tmp;//tmp暂时存放mod; ll ret = 0; for(int i = 0; i <= fpmax; i++) { tmp = mod; if(i > 1) tmp|=(1<<(i-2)); ret += dfs(len-1,(tra*10+i)%2520,tmp,fp&&i==fpmax); } if(!fp) dp[len][tra][mod] = ret; return ret;}ll calc(ll x){ int len = 0; while(x) { num[++len] = x%10; x/=10; } return dfs(len,0,0,true);}int main(){ int t; ll l,r; scanf("%d",&t); memset(dp,-1,sizeof(dp)); while(t--) { scanf("%I64d %I64d",&l,&r); printf("%I64d\n",calc(r)-calc(l-1)); } return 0;}
0 0
- codeforces 55D
- Codeforces 55D
- Codeforces 55D
- codeforces 55D Beautiful numbers
- CodeForces 55D Beautiful numbers
- 【数位DP】 【CodeForces 55D】
- codeforces 55D 数位DP
- Codeforces 55D Beautiful numbers
- CodeForces 55D Beautiful numbers
- codeforces 55D Beautiful numbers
- codeforces 55D Beautiful numbers
- Codeforces 55D 数位DP
- CodeForces 55D Beautiful numbers
- CodeForces 55D - Beautiful numbers
- Codeforces 55d 数位dp
- CodeForces 55D-Beautiful numbers
- CodeForces 55D 数位DP
- Codeforces 55D - Beautiful numbers
- 使用hibernate出现node to traverse cannot be null!
- 原生Ajax的XMLHttpRequest对象使用指南
- swift官方文档和swift视频教程
- C++ 中关于new的介绍
- 不使用额外存储节点的情况下使单链表逆序问题(配图解)
- codeforces 55D
- 理解UART
- 深入分析Parquet列式存储格式
- 解决集群Hive表注释为?的编码问题
- 《大话设计模式》Python版代码实现
- 搬家一次
- [Setting]给VS2008扩展BCGControlBar库
- Linux netstat 命令
- Android View.post(Runnable )