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) ...
随机推荐
- java web启动后执行初始化任务
写一个类继承ApplicationListener,可以直接引用下述代码,然后调用相应的方法. package com.linewell.system; import com.linewell.cac ...
- function $(id) {}表示什么函数
function $(id) {}表示什么函数 一.总结 1.就是简写,不然每次打document.getElementById很烦 二.问题 function $(id) {return docum ...
- Git 安装及使用小结
Git 安装及使用小结 a:focus { outline: thin dotted #333; outline: 5px auto -webkit-focus-ring-color; outline ...
- 关于找不到类org/apache/commons/lang/xwork/StringUtils的问题
在替换最新版的 struts2包的解决过程中.遇到 找不到这两个包org/apache/commons/lang/xwork/StringUtils.org/apache/commons/lang/x ...
- CentOS工作内容(三)配置网络IP地址
CentOS工作内容(三)配置网络IP地址 用到的快捷键 tab 自动补齐(有不知道的吗) ctrl+a 移动到当前行的开头(a ahead) ctrl+u 删除(剪切)此处至开始所有内容 vim 末 ...
- [py][mx]django课程页显示city和机构封面图
city和课程机构信息展示到前台去 organization/views.py from django.views.generic.base import View from organization ...
- 浙大 PAT 乙级 1001-1075 目录索引
1001. 害死人不偿命的(3n+1)猜想 1002. 写出这个数 1003. 我要通过! 1004. 成绩排名 1005. 继续(3n+1)猜想 1006. 换个格式输出整数 1007. 素数对猜想 ...
- Outlier Detection
1)正态分布数据,飘出95%的可能是异常值.变量var正态标准化,|var|<=1.96的可能是异常值,further chk needed!large sample better. 对于偏态分 ...
- Python 之 os.walk()
原文地址https://www.cnblogs.com/JetpropelledSnake/p/8982495.html http://www.runoob.com/python/o ...
- .NET RSA解密、签名、验签
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Sec ...