HDU3652 B-number(数位DP)题解
思路:
这里的状态分为3种,无13和末尾的1,无13且末尾为1,有13,然后DFS
等我搞清楚数位DP就来更新Orz
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 1000000000+5;
int dp[12][15][3],a[20]; //dp[pos][mod][status] //status:0无13和末尾1,1末尾为1,2有13
int dfs(int pos,int mod,int sta,bool limit){
if(pos == -1) return mod == 0 && sta == 2;
if(!limit && dp[pos][mod][sta] != -1) return dp[pos][mod][sta];
int top = limit? a[pos] : 9;
int sta2;
ll ret = 0;
for(int i = 0;i <= top;i++){
sta2 = sta;
if(sta == 0 && i == 1) sta2 = 1;
else if(sta2 == 1 && i == 3) sta2 = 2;
else if(sta2 == 1 && i != 1) sta2 = 0;
ret += dfs(pos-1,(mod*10+i)%13,sta2,limit && i == top);
}
if(!limit) dp[pos][mod][sta] = ret;
return ret;
}
ll solve(int x){
int pos = 0;
while(x){
a[pos++] = x % 10;
x /= 10;
}
return dfs(pos-1,0,0,true);
}
int main(){
int n;
memset(dp,-1,sizeof(dp));
while(~scanf("%d",&n)){
printf("%lld\n",solve(n));
}
return 0;
}
HDU3652 B-number(数位DP)题解的更多相关文章
- 多校5 HDU5787 K-wolf Number 数位DP
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...
- HDU 5787 K-wolf Number 数位DP
K-wolf Number Problem Description Alice thinks an integer x is a K-wolf number, if every K adjacen ...
- BNU 13024 . Fi Binary Number 数位dp/fibonacci数列
B. Fi Binary Number A Fi-binary number is a number that contains only 0 and 1. It does not conta ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- HDU 5898 odd-even number (数位DP) -2016 ICPC沈阳赛区网络赛
题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的 ...
- Fzu2109 Mountain Number 数位dp
Accept: 189 Submit: 461Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description One ...
- 【HDU3652】B-number 数位DP
B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose de ...
- HDU 3709 Balanced Number (数位DP)
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
随机推荐
- flask之表单验证 2018.12.23
#flask的消息闪现依赖于flash库,用户发送的请求方式存储在request模块中 #跳转依赖于redirect模块,还可以通过url_for方法来进行方法上的寻址 from flask impo ...
- Spark 数据源
一.mysql作为数据源 import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession} /** * mysql作为数据源 * ...
- CentOS 7设置Samba共享目录
1. 安装Samba服务 yum -y install samba # 查看yum源中Samba版本 yum list | grep samba # 查看samba的安装情况 rpm -qa | gr ...
- FS Shell命令手册
1. FS Shell 1.1 简介 调用文件系统(FS)Shell命令应使用 bin/hadoop fs <args>的形式. 所有的的FS shell命令使用URI ...
- 【Python】关于Python多线程的一篇文章转载
猪哥推荐的学习网址 http://www.jb51.net/article/110164.htm yeayee ------>更多技巧------>更多源码------>http:/ ...
- [LeetCode] 595. Big Countries_Easy tag: SQL
There is a table World +-----------------+------------+------------+--------------+---------------+ ...
- [LeetCode] All questions numbers conclusion 所有题目题号
Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...
- Bootstrap 网格系统(Grid System)的工作原理 - 媒体查询
媒体查询 媒体查询是非常别致的"有条件的 CSS 规则".它只适用于一些基于某些规定条件的 CSS.如果满足那些条件,则应用相应的样式. Bootstrap 中的媒体查询允许您基于 ...
- Input消除自动记忆功能
在html里就可以直接清除了<input type="text" autocomplete="off"> input 的autocomplete属性 ...
- mongodbtemplate配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...