hdu3652——B-number(数位dp变形)
来源:互联网 发布:藏族音乐软件 编辑:程序博客网 时间:2024/06/04 19:40
Problem Description
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string “13” and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.
Input
Process till EOF. In each line, there is one positive integer n(1 <= n <= 1000000000).
Output
Print each answer in a single line.
Sample Input
13
100
200
1000
Sample Output
1
1
2
2
加了一个还要被13整除的条件,那就在状态数组多加一项表示被13整除的情况,当这项等于0说明能被13整除
#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <cstdio>#include <set>#include <cmath>#include <map>#include <algorithm>#define INF 0x3f3f3f3f#define MAXN 10000000005#define Mod 10001using namespace std;int dight[30],dp[30][3][13];int dfs(int pos,int s,bool limit,int mod){ if(pos==0) return s==2&&mod==0; if(!limit&&dp[pos][s][mod]!=-1) return dp[pos][s][mod]; int end,ret=0; if(limit) end=dight[pos]; else end=9; for(int d=0;d<=end;++d) { int have=s,nmod=(mod*10+d)%13; if(s==1&&d==3) have=2; if(s==0&&d==1) have=1; if(s==1&&d!=1&&d!=3) have=0; ret+=dfs(pos-1,have,limit&&d==end,nmod); } if(!limit) dp[pos][s][mod]=ret; return ret;}int solve(int a){ memset(dight,0,sizeof(dight)); int cnt=1; while(a!=0) { dight[cnt++]=a%10; a/=10; } return dfs(cnt-1,0,1,0);}int main(){ memset(dp,-1,sizeof(dp)); int n; while(~scanf("%d",&n)) { printf("%d\n",solve(n)); } return 0;}
0 0
- hdu3652——B-number(数位dp变形)
- hdu3652——B-number(数位DP)
- hdu3652 B-number(数位dp+dfs)
- hdu3652 B-number(数位dp)
- [hdu3652]B-number(数位dp)
- hdu3652 B-number(数位dp)
- 【数位DP】 hdu3652 B-number
- 【hdu3652】【数位DP】B-number
- 【数位DP】B-number HDU3652
- HDU3652:B-number(数位DP)
- hdu3652 B-number (数位DP)
- HDU3652 B-number 数位DP
- hdu3652 B-number 数位dp
- [HDU3652]B-number && 数位DP
- hdu3652 B-number 数位dp
- hdu3652---B-number(数位dp)
- HDU3652 B-number 数位DP
- hdu3652 B-number 数位dp
- win8.1下Rational Rose7.0的安装
- 输出指定长度的斐波那契数列
- 【codevs】2152 滑雪 记忆化搜索
- Mybatis之typeAliases
- java实现循环链表
- hdu3652——B-number(数位dp变形)
- 第4周 项目5--猴子选大王
- 缓存淘汰算法--LRU算法
- hdoj 5895 Mathematician QSC 【数论----矩阵快速幂求解类斐波那契数列】
- Android开发之局域网聊天软件
- PHP密码找回步骤
- 关于重载赋值操作符需要返回引用
- Poj 3169 Layout【差分约束+SPFA】
- 安装VS2008出错。