HDU 3652B-number 数位dp
来源:互联网 发布:淘宝宝贝突然被删除 编辑:程序博客网 时间:2024/06/08 10:32
G - B-number
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uAppoint description:
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
131002001000
Sample Output
1122
数位dp flag表示状态 mod判断是否能整除
ACcode:
#include <iostream>#include <cstdio>#include <cstring>#define ll long longusing namespace std;int dp[25][25][3];int date[25];int dfs(int pos,int mod,int flag,bool limit){ if(!pos)return mod==0&&flag==2; if(!limit&&dp[pos][mod][flag]!=-1)return dp[pos][mod][flag]; int ret=0; int ed=limit?date[pos]:9; for(int i=0;i<=ed;i++){ int tmp=flag; int modd=(mod*10+i)%13; if(flag==1&&i==3) tmp=2; else if(flag==0&&i==1) tmp=1; else if(flag==1&&i!=1&&i!=3) tmp=0; ret+=dfs(pos-1,modd,tmp,limit&&i==ed); } return limit?ret:dp[pos][mod][flag]=ret;}void doit(int n){ int len=0; while(n){ date[++len]=n%10; n/=10; } printf("%d\n",dfs(len,0,0,1));}int main(){ int n;memset(dp,-1,sizeof(dp)); while(~scanf("%d",&n))doit(n);}
0 0
- HDU 3652--B-number(数位dp)
- HDU 3652 B-number(数位DP)
- [HDU 3652]B-number[数位DP]
- hdu 3652 B-number (数位DP)
- hdu 3652 B-number(数位DP)
- HDU:3652 B-number(数位DP)
- HDU-3652 B-number 数位DP
- HDU 3652 B-number(数位dp模版)
- hdu 3652 B-number(数位dp)
- [数位dp] hdu 3652 B-number
- 【HDU】3652 B-number 数位DP
- hdu 3652 B-number(数位dp)
- HDU 3652 B-number (数位DP)
- HDU 3652 B-number(数位DP)
- HDU 3652 B-number(数位DP)
- hdu 3652 B-number (数位DP)
- 【数位DP】 HDU 3652 B-number
- HDU 3652 B-number(数位DP)
- Bean的生命周期
- Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfile or
- 使用Spring中的jdbcTemplate
- linux shell判断程序是否运行,没有运行则运行程序
- C++实现读取特定路径下文件夹及文件名的方法
- HDU 3652B-number 数位dp
- layer.js 弹出层提交form表单,action重定向
- 关于程序运行时的数据结构
- LeetCode代码分析——6. ZigZag Conversion
- NYOJ 喷水装置(二)(区间覆盖)
- HTML5标签二
- Linux下使Shell 命令脱离终端在后台运行
- C语言宏定义函数与函数的区别
- 重用字体字号对照