题意:

  如果一个整数能被13整除,且其含有子串13的,称为"B数",问[1,n]中有多少个B数?

思路:

  这题不要用那个DFS的模板估计很快秒了。

  状态设计为dp[位数][前缀][模13][是否含13],前缀这一维还是有必要的(由于只有前缀1和其他不同,所以也可以用01来表示是否前缀为1)。递归出口是:出现"13"且mod=0。

 #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#define pii pair<int,int>
#define INF 0x7f3f3f3f
#define LL long long
#define ULL unsigned long long
using namespace std;
const double PI = acos(-1.0);
const int N=; int f[N][N][][], bit[N];
//[位数][前缀][模13的余数][是否包含13] int dfs(int i,int pre,int mod,bool B,bool e)
{
if(i==) return !mod&&B;
if(!e && ~f[i][pre][mod][B]) return f[i][pre][mod][B]; int ans=, m=;
int u= e? bit[i]: ;
for(int d=; d<=u; d++)
{
m=(mod*+d)%;
if( pre==&&d== )
ans+=dfs(i-, d, m, true, e&&d==u);
else
ans+=dfs(i-, d, m, B, e&&d==u);
}
return e? ans: f[i][pre][mod][B]=ans;
} int cal(int n)
{
int len=;
while(n) //拆数
{
bit[++len]=n%;
n/=;
}
return dfs(len, , , false, true);
} int main()
{
//freopen("input.txt","r",stdin);
memset(f,-,sizeof(f));
int n;
while( ~scanf("%d",&n) )
printf("%d\n",cal(n) ); return ;
}

AC代码

最新文章

  1. 决策树及R语言实现
  2. WIN SERVER 2008 R2 VPN
  3. mysql 连接空闲超8小时自动断开连接问题(linux)
  4. 解决mysql数据库连接问题
  5. Bootstrap 基本用法
  6. PHP读取xml方法讲解
  7. Linux 命令 - ls: 列出目录内容
  8. GCC交叉编译链命名
  9. UVA 1617 Laptop
  10. APP性能测试工具
  11. [COGS 1065] 绿豆蛙的归宿
  12. websocket(一)--握手
  13. 第1章 背景 - Identity Server 4 中文文档(v1.0.0)
  14. python条件表达式:多项分支,双向分支
  15. 使用@Autowired时,取值为null
  16. SVN:linux下搭建svn服务器
  17. JSTL的比较运算符有哪些,用例说说它们的作用
  18. 代理服务 SQUID 测试
  19. 如何移除 input type=&quot;number&quot; 时浏览器自带的上下箭头?
  20. ES6 学习笔记之四 对象的扩展

热门文章

  1. 关于REST的一些想法
  2. Http协议-URI和资源
  3. [yii]Trying to get property of non-object
  4. 2014 SCAU_ACM 暑期集训
  5. MS SQL Server的COALESCE函数
  6. c语言的小问题
  7. 一文搞定 Redis 复制(全会的举个手看看)
  8. angularJs 自定义指令传值---父级与子级之间的通信
  9. jar包冲突问题
  10. PAT甲级——1102 Invert a Binary Tree (层序遍历+中序遍历)