HDOJ 2089 数位DP

链接:

http://acm.hdu.edu.cn/showproblem.php?pid=2089

题意:

给你一个区间,问你这个区间有多少个数字不包含4 和 62

代码:

31 int a[20];
32 int dp[20][2];
33
34 int dfs(int pos, int pre, int sta, bool limit) {
35     if (pos == -1) return 1;
36     if (!limit && dp[pos][sta] != -1) return dp[pos][sta];
37     int up = limit ? a[pos] : 9;
38     int res = 0;
39     rep(i, 0, up + 1) {
40         if (i == 2 && pre == 6) continue;
41         if (i == 4) continue;
42         res += dfs(pos - 1, i, i == 6, limit && i == a[pos]);
43     }
44     if (!limit) dp[pos][sta] = res;
45     return res;
46 }
47
48 int solve(int x) {
49     int pos = 0;
50     while (x) {
51         a[pos++] = x % 10;
52         x /= 10;
53     }
54     return dfs(pos - 1, -1, 0, true);
55 }
56
57 int main() {
58     ios::sync_with_stdio(false), cin.tie(0);
59     int l, r;
60     while (cin >> l >> r, l + r) {
61         memset(dp, -1, sizeof(dp));
62         cout << solve(r) - solve(l - 1) << endl;
63     }
64     return 0;
65 }
时间: 2024-08-11 05:34:59

HDOJ 2089 数位DP的相关文章

HDU 2089 数位dp入门

开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #include<math.h> #include<queue> using namespace std; int n,m; /

hdu 2089(数位DP)

不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 32234    Accepted Submission(s): 11447 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可

HDU 不要62 2089 数位DP

属于数位DP中的模版题 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; #define MOD 2520 int dp[20][2];//dp[数字的长度][数字的第一位数字]: int bit[20], p = 0; int df

HDU 2089 数位dp/字符串处理 两种方法

不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 34525    Accepted Submission(s): 12493 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可

hdu 2089 不要62 【数位DP】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位DP模板题,测试板子 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include <string> #include <functional> #include &l

hdu 2089 不要62 (数位dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 思路:用变量记录吉利数,和最高位为2的吉利数还有不是吉利数的个数... code: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[10][3]; //dp[i][j] ,i表示位数,j表示状态<pre name="code"

[ACM] hdu 2089 不要62(数位Dp)

不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 19043    Accepted Submission(s): 6442 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就

HDU 2089 不要62(数位DP,三种姿势)

HDU 2089 不要62(数位DP,三种姿势) ACM 题目地址:HDU 2089 题意: 中文题意,不解释. 分析: 100w的数据,暴力打表能过 先初始化dp数组,表示前i位的三种情况,再进行推算 直接dfs,一遍搜一变记录,可能有不饥渴的全部算和饥渴的部分算情况,记录只能记录全部算(推荐看∑大的详细题解Orz) 代码: 1. 暴力 (以前写的) /* * Author: illuz <iilluzen[at]gmail.com> * File: 2089_bf.cpp * Create

找规律/数位DP HDOJ 4722 Good Numbers

题目传送门 1 /* 2 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () 3 http://www.cnblogs.com/crazyapple/p/3315436.html 4 数位DP:http://blog.csdn.net/cyendra/article/details/11606209 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <algorithm> 9