hdu3652(数位dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3652
题意:求1~n含有13且能被13整除的数的个数。
分析:数位dp,dp数组加一维来维护到pos位模13的余数,则dp[pos][mod][2]表示非限制条件下到pos位模13余mod且已含有13的总个数,dp[pos][mod][1]表示没含有13但前一位是1且模13余mod的总个数,dp[pos][mod][0]表示没含有13前一位不为1模13余mod的总个数。。。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 10007
#define inf 0x3f3f3f3f
#define N 100010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int dp[][][];
int dig[];
int dfs(int pos,int pre,int md,int flag,int limit)
{
if(!pos)return flag&&md==;
if(!limit&&flag&&~dp[pos][md][])return dp[pos][md][];
if(!limit&&!flag&&pre==&&~dp[pos][md][])return dp[pos][md][];
if(!limit&&!flag&&pre!=&&~dp[pos][md][])return dp[pos][md][];
int len=limit?dig[pos]:;
int ans=;
for(int i=;i<=len;i++)
{
ans+=dfs(pos-,i,(md*+i)%,flag||(pre==&&i==),limit&&i==len);
}
if(!limit)
{
if(flag)dp[pos][md][]=ans;
else if(pre==)dp[pos][md][]=ans;
else dp[pos][md][]=ans;
}
return ans;
}
int solve(int x)
{
int len=;
while(x)
{
dig[++len]=x%;
x/=;
}
return dfs(len,,,,);;
}
int main()
{
int n;
while(scanf("%d",&n)>)
{
memset(dp,-,sizeof(dp));
printf("%d\n",solve(n));
}
}
hdu3652(数位dp)的更多相关文章
- HDU3652(数位dp)
A - B-number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descri ...
- hdu3652 数位dp记忆化搜索
从未见过的船新版本数位dp,,省去了预处理过程,直接进行计算 #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- HDU3652 B-number —— 数位DP
题目链接:https://vjudge.net/problem/HDU-3652 B-number Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- 【HDU3652】B-number 数位DP
B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose de ...
- 数位DP HDU3652
B-number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu3652 B-number 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3652 题意就是求区间内能被13整除并且包含”13“的数字的个数 感觉是比较中等的数位DP题目 我用的记 ...
- 【Hdu3652】B-number(数位DP)
Description 题目大意:求小于n是13的倍数且含有'13'的数的个数. (1 <= n <= 1000000000) Solution 数位DP,题目需要包含13,且被13整除, ...
- HDU3652 B-number(数位DP)题解
思路: 这里的状态分为3种,无13和末尾的1,无13且末尾为1,有13,然后DFS 等我搞清楚数位DP就来更新Orz 代码: #include<iostream> #include< ...
- 【hdu3652】数位dp(浅尝ACM-A)
向大佬学习 第一次写博客有点紧张,也算是小萌新的突破吧 这次主要是总结一下校内的ACM比赛的各种题,主要是新思路以及学到的新知识 先放一张 下面开始说正事 题面 A wqb-number, or B- ...
随机推荐
- perl 匿名函数传参
$subref=sub { my $a=shift; return $a; }; print $subref->("xxyyzz");
- 基于visual Studio2013解决C语言竞赛题之1091多项式
题目 解决代码及点评 /************************************************************************/ /* ...
- [置顶] 遇到难题(bug)的解决方法心得
今天早上花了2个小时解决一个问题...界面抖动.. 最近把淄博项目的界面用BT改了,后来发现4个界面之间切换会抖动.. 就是整个界面会左右抖动... 文章出处: PHP攻城师 www.phpgcs.c ...
- 【LeetCode从零单排】No 3 Longest Substring Without Repeating Characters
题目 Given a string, find the length of the longest substring without repeating characters. For exampl ...
- MySqlClient访问tinyint字段返回布尔值
原文 MySqlClient访问tinyint字段返回布尔值 症状: 使用MySqlClient访问tinyint unsign 字段返回布尔值 true 和 false,但 ...
- MySQL备份方案-->(利用mysqldump以及binlog二进制日志)
MySQL备份方案-->(利用mysqldump以及binlog二进制日志) 随着数据不 ...
- 设计模式(三)-- 适配器模式(Adapter)
适配器模式(Adapter) 考虑一个记录日志的应用,由于用户对日志记录的要求很高,使得开发人员不能简单地采用一些已有的日志工具或日志框架来满足用户的要求,而需要按照用户的要求重新开发新的日志管理系统 ...
- 为HttpStatusCodeResult加入customErrors
asp.net mvc的action返回值为HttpStatusCodeResult时的customErrors总是不起作用 (404和exception时的500,因为他们并不是HttpStatus ...
- 王立平--android中的anim(动画)
简单有用步骤: 1.新建anim目录. 2.在anim下新建xml文件, 3.在xml下编写自己须要动画. 简单样例: 给Imageview加入动画 public class MainActivity ...
- Qt 向word中插入文字(使用QAxWidget和QAxObject)
pro 文件中要加入 CONFIG += qaxcontainer 2. main.cpp #include <QApplication> #include <QAxWidget&g ...